Created
February 10, 2019 22:18
-
-
Save SchlenkR/8400b2089e5e0b5be9ce498cd3837453 to your computer and use it in GitHub Desktop.
This file contains 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 RowPointer = int | |
type Writer = Writer of (RowPointer -> RowPointer) | |
let run (f:Writer) = match f with | Writer f -> f | |
type Cursor() = | |
member this.Bind(m: Writer, f: unit -> Writer) = | |
Writer(fun rp -> | |
let res = f() |> run | |
let newRp = rp |> run m | |
res newRp) | |
member this.Return (x:Unit) = Writer (fun a -> a) | |
let cursor = Cursor() | |
let write content = | |
Writer (fun (row:RowPointer) -> | |
printfn "WRITING ROW %d: %s" row content | |
row + 1) | |
let x = cursor { | |
do! (write "Hello 1") | |
do! (write "Hello 2") | |
[1..5] | |
|> List.map (fun v -> | |
do! (write "Hello 2") | |
) | |
|> ignore | |
return () | |
} | |
(run x) 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment