This site is updated infrequently. For up-to-date information, please visit the new OCaml website at ocaml.org.

[Caml-list] Y combinator and type-checking
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2004-07-02 (17:48) From: Brian Hurt Subject: Re: [Caml-list] Y combinator and type-checking
```On Fri, 2 Jul 2004, Martin Berger wrote:

> now i annotate the definition above with the types just
> inferred:
>
>      let rec y  ( f : ( 'a -> 'b ) -> 'a -> 'b )
>             : ( ( 'a -> 'b ) -> 'a -> 'b ) -> 'a -> 'b
>        = f (fun x -> (y f) x );;

This is where your mistake is.  Don't duplicate the type of f.  Instead,
you should have done:

let rec y (f : ('a -> 'b) -> 'a -> 'b) : 'a -> 'b = f (fun x -> (y f) x);;

And now it works:
\$ ocaml
Objective Caml version 3.07

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

--
"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
- Gene Spafford
Brian

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

```