Skip to content

Instantly share code, notes, and snippets.

@ebresafegaga
Last active May 12, 2021 15:10
Show Gist options
  • Save ebresafegaga/d728af70bc92d36c71b6149d84bcc0a9 to your computer and use it in GitHub Desktop.
Save ebresafegaga/d728af70bc92d36c71b6149d84bcc0a9 to your computer and use it in GitHub Desktop.
Fix point combinator
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)
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