Browse thread
Re: [Caml-list] let rec and polymorphic functions
-
David Allsopp
-
Jeremy Yallop
- David Allsopp
-
Virgile Prevosto
- Jeremy Yallop
- Jon Harrop
-
Jeremy Yallop
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| 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 <jeremy.yallop@ed.ac.uk> 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
Jeremy.
>
> 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'