-
-
Save ebresafegaga/d728af70bc92d36c71b6149d84bcc0a9 to your computer and use it in GitHub Desktop.
Fix point combinator
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
let rec fix f = f (fun x -> (fix f) x) | |
(* let rec fix f = f (fix f) *) | |
let fix1 = | |
let rec fix f = lazy (f (fix f)) in | |
fix | |
let fact = | |
fix (fun fact n -> | |
match n with | |
| n when n <= 1 -> 1 | |
| n -> fact (n-1) + fact (n-2)) | |
let map = | |
fix (fun map f xs -> | |
match xs with | |
| x :: xs -> f x :: map f xs | |
| [] -> []) | |
let () = | |
let n = 5 in | |
Printf.printf "The factorial of %d is %d" n (fact n) |
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
type 'a recc = In of ('a recc -> 'a) | |
let out (In f) = f | |
let u f = out f f | |
let y g = | |
u (In (fun f -> g (out f f))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment