Created
November 9, 2020 12:29
-
-
Save fjod/bd1e18320a4123c17fdc467a7d7df0d3 to your computer and use it in GitHub Desktop.
F# CE from Skeet&Petrichek book
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
type TheValue<'a> = | |
| Value of 'a | |
| None | |
let ReadInt() = | |
match Console.ReadLine() |> Int32.TryParse with | |
| true , v -> Value v | |
| _ -> None | |
type TheValueBuilder() = | |
member x.Bind(v,f) = | |
match v with | |
| Value v -> f(v) | |
| None -> None | |
member x.Return(v) = Value(v) | |
let value = new TheValueBuilder() | |
[<EntryPoint>] | |
let main argv = | |
let printTheValue (n:TheValue<int>) = | |
match n with | |
| Value n -> printfn "%i" n | |
| None -> printf "noneValue" | |
value{ | |
let! a = ReadInt() | |
Console.WriteLine ("you entered" + a.ToString()) | |
let! b = ReadInt() | |
Console.WriteLine ("you entered" + b.ToString()) | |
let add = a + b | |
return add | |
} |> printTheValue | |
Console.WriteLine ("result is above") | |
0 // return an integer ex | |
// it code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment