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
| type OptionBuilder() = | |
| member self.Bind(input, operation) = Option.bind operation input | |
| member self.Delay (operation:(unit -> 'a option)) = operation () | |
| member self.Return input = Some input | |
| member self.ReturnFrom (input : 'a option) = input | |
| let option = OptionBuilder();; |
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
| let result = option { | |
| let! y = f x | |
| let! z = g y | |
| return! h z};; |
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
| builder {let! pattern = expr | |
| compound_expr } |
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
| builder.Bind(expr, (fun pattern -> compound_expr)) |
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
| let ReturnAsync x = async { return x } | |
| let (>>=!) m f = async { return Async.RunSynchronously(f(Async.RunSynchronously m)) } | |
| let (>>!) m1 m2 = m1 >>=! fun () -> m2 | |
| let (>=>!) f g = fun x -> ((f x) >>=! g) | |
| let ApplyAsync m1 m2 = | |
| m1 >>=! fun f -> | |
| m2 >>=! fun x -> | |
| ReturnAsync (f x) | |
| let LiftAsync f = ApplyAsync (ReturnAsync f) | |
| let SequenceAsync (l : _ list) = |
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
| let Half_Adder x y = (XOR x y, AND x y);; |
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
| let fst (a,b) = a;; | |
| let snd (a,b) = b;; |
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
| type Point = { x: int; y: int; move: Point -> Point } | |
| let rec makePoint vx vy = | |
| let doMove p = makePoint (vx + p.x) (vy + p.y) | |
| { x = vx; y = vy; move = doMove };; |
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
| let p = (makePoint 1 2).move(makePoint 2 3);; |
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
| {p with x = 6; y = 0 };; |