Skip to content

Instantly share code, notes, and snippets.

@palladin
Created July 2, 2012 10:56
Show Gist options
  • Save palladin/3032692 to your computer and use it in GitHub Desktop.
Save palladin/3032692 to your computer and use it in GitHub Desktop.
Y(n) Polyvariadic fixpoint
let rec Y f x = f (Y f) x
let rec Y2 f1 f2 =
let f1' = Y (fun f1' -> f1 f1' (Y (fun f2' -> f2 f1' f2')))
let f2' = Y (fun f2' -> f2 (Y (fun f1' -> f1 f1' f2')) f2')
f1', f2'
// Example
let even, odd =
Y2 (fun even odd x ->
x = 0 || odd (x-1))
(fun even odd x ->
x <> 0 && even (x-1))
even 42 // true
odd 42 // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment