Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] let rec and polymorphic functions
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Virgile Prevosto <virgile.prevosto@m...>
Subject: Re: [Caml-list] let rec and polymorphic functions
Le mer 27 jun 2007 12:12:34 CEST,
Jeremy Yallop <jeremy.yallop@ed.ac.uk> a écrit :

> David Allsopp wrote:
> > let rec id x = x
> > and _ = id 0
> > in
> >   id (); (* *** *)
> >   id 1;;
> > 
> This isn't really "the equivalent SML", since the definition of `id
> x' and the application `id 0' aren't in the same recursive group.
> The equivalent in SML would be something like
> 
>     let val rec id = fn x => x
>             and _  = id 0
>         in
>            id ();
>            id 1
>     end
> 
> 
> OCaml seems a little inconsistent here, actually.  The application
> `id 0' is only valid as the rhs of let rec because the compiler can 

Well, it just seems that Ocaml performs type inference before checking
the validity of the recursive definition. If you give a well-typed
term, it will complain about a forbidden rhs of let rec:

        Objective Caml version 3.10.0

#  let rec id = fun x -> x and _foo = id 0 in id 1;;
This kind of expression is not allowed as right-hand side of `let rec'
-- 
E tutto per oggi, a la prossima volta.
Virgile