Newbie here. Somebody can point to useful other resources for F#?
https://fsharpforfunandprofit.com is great. I'm enjoying Don Syme's book "Expert F# 4.0" as well.
Get Started with F# as a C# developer
21–30 of 60 posts
Re: Get Started with F# as a C# developer
#22Re: Get Started with F# as a C# developer
#23Newbie here. Somebody can point to useful other resources for F#?
Is there a really good reason to choose to use F# over C#? Or does it really just come down to preference?
1. Immutable values by default avoids whole categories of problems. Just for one example, you can't have a data race between two threads if all the public values accessible from each thread are guaranteed immutable.
2. F# forces all cases to be handled. You've doubtless run into C# code that has a switch statement that doesn't have cases for all possible inputs, and no default case. F# doesn't have a direct equivalent of "switch" at all, but it does enforce completeness in the equivalents it does have. For example, it's illegal in F# to say something like "if foo > 1 then ... elif foo 3. F# has units of measure data types. Ever had an application bug because you've incorrectly passed a bare "int" value holding milliseconds to a function expecting seconds? I have. F# lets you define your units as part of the data type, so that it's a compiler error to pass milliseconds to a function expecting seconds.
I could go on, but as you can see, there really are substantial differences in practice between F# and C# code.
Re: Get Started with F# as a C# developer
#24Re: Get Started with F# as a C# developer
#25Ask HN: I've toyed around with F# and I kinda like it but I've never dug deep enough into it to answer the question: can I use this for 'real life' code as part of an existing C# desktop application for instance, e.g. build some F# into an assembly which is callable from C#? Without tons of hassle? What are good samples of real life application code in F#?
> Without tons of hassle? Well, yes and no. You definitely can do this, and for some applications it's worth it, but often the overhead at the API level will make you cringe. APIs designed for C# are very different than APIs designed for F#, to account for partial application of functions, sum-types, non-nullability, immutability and value-like behavior by default from F# types, and also to make good use of F#'s type…
If there were a ton of F# libraries that showed how to create functional APIs people could learn from them by using them the same way a lot people learn OOP by using APIs.
As it is now the only way to get into F# is to have a group who really wants to do it and learn. Otherwise it's just an uphill battle.
Re: Get Started with F# as a C# developer
#26Ask HN: I've toyed around with F# and I kinda like it but I've never dug deep enough into it to answer the question: can I use this for 'real life' code as part of an existing C# desktop application for instance, e.g. build some F# into an assembly which is callable from C#? Without tons of hassle? What are good samples of real life application code in F#?
I can't share the code with you, but I did just that on a proprietary app for my company. Only the GUI shell of the app is in C#, and that only because the GUI builder features of Visual Studio can only generate C# code. All of the "real" code in that app is in an F# library, which you add to the Visual Studio solution just like you would any other C# helper library. When you add a source file to that library, it's a…
And there is the famous line "Functional programming? We did functions 30 years ago. No big deal".
Re: Get Started with F# as a C# developer
#27I'll take MS's commitment to F# seriously when they stop treating it like a 2nd class citizen. .NET Core 1.0 has been out for over a year, .NET Core 2.0 is in preview and there is ZERO support for F# with .NET Core in Visual Studio 2017. Yes you can use VSCode, but VSCode is no Visual Studio - it's a text editor on steroids, not a proper IDE that most C# developers have come to expect.
I don't know how much of this is the F# team's fault, but F# the 'eco-system' feels like it's going backwards at the moment.
Re: Get Started with F# as a C# developer
#28Ask HN: I've toyed around with F# and I kinda like it but I've never dug deep enough into it to answer the question: can I use this for 'real life' code as part of an existing C# desktop application for instance, e.g. build some F# into an assembly which is callable from C#? Without tons of hassle? What are good samples of real life application code in F#?
Re: Get Started with F# as a C# developer
#29Newbie here. Somebody can point to useful other resources for F#?
https://github.com/rspeele/CSharpFSharpPhrasebook
This does not sell the language -- it doesn't show off anything interesting you can do in F# that you can't in C#. There are other resources for "why F#". This is for C# developers who are convinced that they want to learn, but are annoyed by not being able to quickly look up how to do the things that they're familiar with from C#.
Re: Get Started with F# as a C# developer
#30 // Flip the BST using pattern matching!
let rec flip bst =
match bst with
| Empty -> bst
| Node(item, left, right) -> Node(item, flip right, flip left)
Without type annotations, how can it tell the flip takes an instance of BST as the parameter?