Created
July 2, 2012 10:56
-
-
Save palladin/3032692 to your computer and use it in GitHub Desktop.
Y(n) 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
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