Tutorial by Examples

An Option is a discriminated union with two cases, None or Some. type Option<'T> = Some of 'T | None
In functional programming languages like F# null values are considered potentially harmful and poor style (non-idiomatic). Consider this C# code: string x = SomeFunction (); int l = x.Length; x.Length will throw if x is null let's add protection: string x = SomeFunction (); int l = x ...
Error handling is important but can make an elegant algorithm into a mess. Railway Oriented Programming (ROP) is used to make error handling elegant and composable. Consider the simple function f: let tryParse s = let b, v = System.Int32.TryParse s if b then Some v else None let f (g : ...
It is not a good idea to expose Option types to C# code, as C# does not have a way to handle them. The options are either to introduce FSharp.Core as a dependency in your C# project (which is what you'd have to do if you're consuming an F# library not designed for interop with C#), or to change None...

Page 1 of 1