Richard Jones <

rich@...> writes:

> On Wed, Oct 01, 2003 at 12:21:18PM +0200, Remi Vanicat wrote:

>> Ocaml make a lot of statical check. So he forbid what you are trying

>> (the right-hand side of let rec must not be the result of the

>> evaluation of some function).

>

> Similar to a problem I've just encountered. Here's my minimal test case:

>

> # type tree = Leaf of int | Node of (string * tree) list ;;

> type tree = Leaf of int | Node of (string * tree) list

>

> # let empty = Node [] ;;

> val empty : tree = Node []

>

> # let top = Node [ "Entry", entry1 ]

> and entry1 = empty ;;

> Unbound value entry1

>

> # let rec top = Node [ "Entry", entry1 ]

> and entry1 = empty ;;

> This kind of expression is not allowed as right-hand side of `let

> rec'

I was surprised this doesn't work, so I've just test it :

# type tree = Leaf of int | Node of (string * tree) list ;;

type tree = Leaf of int | Node of (string * tree) list

# let empty = Node [] ;;

val empty : tree = Node []

# let rec top = Node [ "Entry", entry1 ]

and entry1 = empty ;;

val top : tree = Node [("Entry", Node [])]

val entry1 : tree = Node []

This is working... in ocaml 3.07, but not in ocaml 3.06. Good news

isn't it ?

By the way, camlp4 give you the possibility of defining a where clause

(it is one easily available example).

So you could write things like :

let top = Node [ "Entry", entry1 ]

where entry1 = empty ;;

which is translated by camlp4 into :

let top =

let entry1 = empty in

Node [ "Entry", entry1 ]

before been compiled by ocaml

[...]

--

RĂ©mi Vanicat

remi.vanicat@...