codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
let rec fact1 n = match n with 0 -> 1 | n -> n * fact2 (n - 1) and fact2 n = if n < 2 then 1 else n * fact3 (n - 1) and fact3 = function | 0 -> 1 | n -> n * fact1 (n - 1) ;; (* チューリングの賢人鳥 *) let rec turing's_sage f x = f (turing's_sage f) x ;; (* カリーの雲雀 *) let lark x (`M y) = x (fun z -> y (`M y) z) ;; let curry's_sage f x = lark f (`M (lark f)) x ;; print_int (fact1 5) ;; print_string "\n" ;; print_int (fact2 5) ;; print_string "\n" ;; print_int (fact3 5) ;; print_string "\n" ;; print_int (turing's_sage (fun f x -> if x = 0 then 1 else x * (f (x-1))) 5) ;; print_string "\n" ;; print_int (curry's_sage (fun f n -> if n = 0 then 1 else n * (f (n-1))) 5) ;;
Private
[
?
]
Run code