Version française
Home     About     Download     Resources     Contact us    

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

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: 2007-06-27 (13:05)
From: Jeremy Yallop <jeremy.yallop@e...>
Subject: Re: [Caml-list] let rec and polymorphic functions
Virgile Prevosto wrote:
> Le mer 27 jun 2007 12:12:34 CEST,
> Jeremy Yallop <> a écrit :
>> 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:

You're right; I'd overestimated the extent of the analysis.  Note that 
applications on the rhs of let rec are acceptable if there's no 
recursion at all involved in the application:

   let id x = x in
   let rec f = id id
       and g x = g (f x)
    in g


>         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'