Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
1
Task/Y-combinator/OCaml/y-combinator-1.ocaml
Normal file
1
Task/Y-combinator/OCaml/y-combinator-1.ocaml
Normal file
|
|
@ -0,0 +1 @@
|
|||
let fix f g = (fun x a -> f (x x) a) (fun x a -> f (x x) a) g
|
||||
1
Task/Y-combinator/OCaml/y-combinator-2.ocaml
Normal file
1
Task/Y-combinator/OCaml/y-combinator-2.ocaml
Normal file
|
|
@ -0,0 +1 @@
|
|||
let fix f = (fun (`X x) -> f(x (`X x))) (`X(fun (`X x) y -> f(x (`X x)) y));;
|
||||
27
Task/Y-combinator/OCaml/y-combinator-3.ocaml
Normal file
27
Task/Y-combinator/OCaml/y-combinator-3.ocaml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
type 'a mu = Roll of ('a mu -> 'a);;
|
||||
|
||||
let unroll (Roll x) = x;;
|
||||
|
||||
let fix f = (fun x a -> f (unroll x x) a) (Roll (fun x a -> f (unroll x x) a));;
|
||||
|
||||
let fac f = function
|
||||
0 -> 1
|
||||
| n -> n * f (n-1)
|
||||
;;
|
||||
|
||||
let fib f = function
|
||||
0 -> 0
|
||||
| 1 -> 1
|
||||
| n -> f (n-1) + f (n-2)
|
||||
;;
|
||||
|
||||
(* val unroll : 'a mu -> 'a mu -> 'a = <fun>
|
||||
val fix : (('a -> 'b) -> 'a -> 'b) -> 'a -> 'b = <fun>
|
||||
val fac : (int -> int) -> int -> int = <fun>
|
||||
val fib : (int -> int) -> int -> int = <fun> *)
|
||||
|
||||
fix fac 5;;
|
||||
(* - : int = 120 *)
|
||||
|
||||
fix fib 8;;
|
||||
(* - : int = 21 *)
|
||||
1
Task/Y-combinator/OCaml/y-combinator-4.ocaml
Normal file
1
Task/Y-combinator/OCaml/y-combinator-4.ocaml
Normal file
|
|
@ -0,0 +1 @@
|
|||
let rec fix f x = f (fix f) x;;
|
||||
Loading…
Add table
Add a link
Reference in a new issue