[Haskell-beginners] Y-combinator

Jon Harrop jon at ffconsultancy.com
Wed Feb 24 15:41:01 EST 2010


OCaml can do this:

$ ocaml -rectypes
        Objective Caml version 3.11.1

# let fix f = (fun x -> f(x x)) (fun x y -> f(x x) y);;
val fix : (('a -> 'b) -> 'a -> 'b) -> 'a -> 'b = <fun>

# fix (fun f -> function 0 -> 1 | n -> n*f(n-1)) 10;;
- : int = 3628800

Haskell 98 doesn't seem to be able to type check that definition of the 
y-combinator directly. Is there a Haskell extension that would let it handle 
this?

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e


More information about the Beginners mailing list