by FrustratedMonky · 3y ago · 0 comments
IF you have grown up doing objects, or C#, and thinking with variables. Then 'a=1' means a memory for variable a has a 1, and you should be able to change that. But it is really a like a function where the function returns a 1.
'let a = 1' is not assigning the value 1 to variable a.
'a' is a function that returns a 1.
I think this is biggest reason why people trying to learn functional programming in languages that don't enforce immutability, have a harder time than with languages that do enforce it.
Like moving to another country, and the people around you purposely don't speak English so you have to learn the language. If the did speak English to help you, then you wouldn't learn the language.
Enforcing immutability is like this.
Mutable variables are better explained as slots or cells, I think. Both OCaml and Rust have a concept of ref cells, for example (and they entirely replace mutable local variables in OCaml).
1: https://en.m.wikipedia.org/wiki/Variable_(mathematics) 2: https://en.m.wikipedia.org/wiki/Variable_(computer_science)
I can imagine that trying to translate C# to F# would be horrible. That is going against the grain.
I'd encourage you to have a look at the SAFE stack it's really nice to use. https://safe-stack.github.io/
https://zaid-ajaj.github.io/the-elmish-book/#/
https://github.com/giraffe-fsharp/Giraffe/blob/master/DOCUME...
https://bulma.io/documentation/
https://medium.com/@zaid.naom/introducing-fable-remoting-aut...
That said I don't think there are any features that I'm missing out on being at .Net 6.
I think there is a limited number of maintainers of the SAFE template so they might not be able to keep on the bleeding edge. But it's not that hard to update the components to the latest versions. As can be seen on this waiting pull request https://github.com/SAFE-Stack/SAFE-template/pull/564
I should also mention that when I've hit issues with packages not working on the latest .Net version I've asked in the F# slack and twice had the maintainers fix things within a day so it would run at the latest version.
In any case. I get it. If you have done ASP.NET, and C#, then suddenly this F# way of building web pages by programming through combining functions, it is hard to get over the hump. Like brain has to re-change how to think through the whole flow. Really, F# on the web is like ELM.
I like https://websharper.com/
but other use this https://suave.io/
Giraffe is nice because it is itself built "just" as ASP.NET Core Middleware so it plays a bit more nicely than Suave with a mixed stack of C#-defined Middleware.
It's more likely you accidentally fall back into just translating C# patterns to non-idiomatic F# with Giraffe, but it's also nicer when in that case of needing to live in both worlds and use a mixture of libraries built for C# ASP.NET projects.