Created
August 9, 2022 12:55
-
-
Save Zeta611/112bdd2fd669241ef3c9b23ce9104093 to your computer and use it in GitHub Desktop.
[Fixed-point combinator in OCaml] Fixed-point combinator (Z combinator) in OCaml. Y combinator is not available, as OCaml is a strict language. #demo
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 fix = Fix of ('a fix -> 'a) | |
let fix f = | |
(fun (Fix x as fix) -> f (fun z -> x fix z)) | |
(Fix (fun (Fix x as fix) -> f (fun z -> x fix z))) | |
let factorial = fix @@ fun f n -> if n <= 0 then 1 else n * f (n - 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment