Re:Fable 3: F# to JavaScript compiler
by Serow225 on Saturday December 05, 2020 @01:55PM
(#25317201)
I think it will get better in F# 5.1, which adds native C# Task support...
https://github.com/fsharp/fslang-design/blob/master/RFCs/FS-...
Re:Fable 3: F# to JavaScript compiler
by seankearon on Sunday December 06, 2020 @04:50AM
(#25322385)
In the meantime, you can use the fantastic TaskBuilder.fs for C# Task support and interop.
https://www.nuget.org/packages/TaskBuilder.fs/ https://github.com/rspeele/TaskBuilder.fs
Example here is the String doc[1]. Way down you see all the methods. Some of the methods have overloads (multiple variants). Pretty straightforward here. (E.g. `"mystring".Contains("ring")`)
Where it gets more verbose and finicky is when the API takes a C# callback. Even more complex is if it’s asynchronous so it takes a C# callback as a Task.
An example being the `.Use` method for defining server middleware.[2]
To see how it’s done, here’s a gist I found.[3] Notice how the function for requestHandler is verbosely annotated with Func<> and RequestDelegate, etc.
Luckily this isn’t the norm, most APIs are less complicated. Even so, you write a wrapper (abstraction) around that complexity and only look at your wrapper. Which is why someone in this thread said to leave them in a dark corner.
[1]: https://docs.microsoft.com/en-us/dotnet/api/system.string?vi...
[2]: https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnet...
[3]: https://gist.github.com/kspeakman/7870a75283f6942dd96ff34a03...