Created
May 9, 2018 16:48
-
-
Save dsyme/fb5c70ce6b16ac3047b8ceae057ccccb 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
let Stack() = System.Diagnostics.StackTrace(true) | |
type Computation<'T> = C of System.Diagnostics.StackTrace * (unit -> 'T) | |
[<System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)>] | |
let bind (C (fstack, f)) k = C(Stack(), fun () -> let (C (f2stack, f2)) = k (f ()) in f2()) | |
[<System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)>] | |
let ret x = C (Stack(), fun () -> x) | |
let add c1 c2 = bind c1 (fun v1 -> bind c2 (fun v2 -> ret (v1 + v2))) | |
let stack msg (C (stack , f)) = C (stack, (fun () -> System.Console.WriteLine("----{0}-----\n{1}\n----------", msg, stack); f())) | |
let run (C (_,f)) = f () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gives stack: