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
module state = | |
type StateM<'s,'a> = abstract Apply : 's -> ('s -> 'a -> 'r) -> 'r | |
let mkStateM (f : 's -> 's * 'a) : StateM<'s,'a> = | |
{ new StateM< 's , 'a > with member __.Apply s k = match f s with (s,a) -> k s a } | |
let runStateM (m : StateM<'s,'a>) : 's -> 's * 'a = fun s -> | |
m.Apply s (fun s a -> (s,a)) | |
// defined directly to avoid the value restriction. |
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
module tramp | |
// we want to use an existential type, but F# makes that complicated so obj it is. | |
type Tree = | Bind of Tree * (obj -> Tree) | |
| Delay of (unit -> Tree) | |
| Leaf of obj | |
type FnStack<'a,'b> = | End of ('a -> 'b) | |
| Cons of ('a -> Tree) * FnStack<obj,'b> |
OlderNewer