Created
December 9, 2011 14:46
-
-
Save palladin/1451796 to your computer and use it in GitHub Desktop.
Polyvariadic fixpoint
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
// http://okmij.org/ftp/Computation/fixed-point-combinators.html | |
let force (value : Lazy<_>) = value.Force() | |
let fix f = let rec x = lazy (f x) in x | |
let fix' (fs : list<Lazy<list<'a -> 'b>> -> 'a -> 'b>) : Lazy<list<'a -> 'b>> = | |
fix (fun r -> fs |> List.map (fun f -> f r)) | |
let fe l x = | |
let [e; o] = force l | |
x = 0 || o (x-1) | |
let fo l x = | |
let [e; o] = force l | |
x <> 0 && e (x-1) | |
let l = fix' [fe; fo] | |
let [e; o] = force l | |
e 42 // true | |
o 42 // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment