fsharp / fslang-suggestions

The place to make suggestions, discuss and vote on F# language and core library features
346 stars 21 forks source link

Implement implicit conversion between F# fun to .NET generic Func<> for ASP.NET minimal API. #1334

Open oleksandr-bilyk opened 1 year ago

oleksandr-bilyk commented 1 year ago

I propose F# implicitly cast F# fun with parameter attributes to C# delegate. It will help to write ASP.NET minimal API in short way

image

To do the same on F# I must create separate function.

image

C# looks better for this

image
smoothdeveloper commented 1 year ago

@oleksandr-bilyk I think right now it does already do it, if you pass the lambda in the call.

Also, should this work with any delegate type instead? I'm not keen on "Func is better" stuff which is already having few edge cases in overload resolution.

smoothdeveloper commented 1 year ago

Likely a special case for #1131

brianrourkeboll commented 1 year ago

You can write some code to work around this if you want, like I did in https://github.com/brianrourkeboll/FSharp.AspNetCore.WebAppBuilder; a few others have experimented with similar things, I believe, including @lucasteles, who opened #1131.

gurustron commented 9 months ago

Also note that AFAIK the attributes currently are not captured, i.e. since FromServices will be correctly inferred everything will work as expected.

lucasteles commented 8 months ago

@brianrourkeboll Yes, I ended up creating this https://github.com/lucasteles/FSharp.MinimalApi also