Skip to content

Instantly share code, notes, and snippets.

@palladin
Created December 9, 2011 14:46
Show Gist options
  • Save palladin/1451796 to your computer and use it in GitHub Desktop.
Save palladin/1451796 to your computer and use it in GitHub Desktop.
Polyvariadic fixpoint
// 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