Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] trouble w/ recursive let definitions.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Shishir Ramam <sramam@g...>
Subject: [Caml-list] trouble w/ recursive let definitions.
Hi,
I might be missing something here, but recursive let definitions have me a 
little confused. The two cases below narrow down my problem. Why is case-2
invalid?

A reading of the Ocaml User manual did not suggest that case 2 should
be invalid.
I have pasted the relevent section of the manual. 

I am using Ocaml 3.07+2 precompiled win32 binaries. 

Thanks in advance for any help. 
-shishir


Case 1:
----------
let rec p1 s = 
    p2 s
and p2 s = 
    print_string s;;

This works fine. 

Case 2:
----------
let q0 i = 
    print_int i;
and rec q1 s = 
    q2 s
and q2 s = 
    print_string s;;

Characters 33-36:
  and rec q1 s = 
      ^^^
Syntax error

------------------------------
>From the User manual (3.07+2/win32) , Section 6.7.1 pg 109

Recursive definitions of names are introduced by let rec:
       let rec pattern1 = expr1 and . . . and patternn = exprn in expr
The only difference with the let construct described above is that the bindings
of names to values performed by the pattern-matching are considered already
performed when the expressions expr1 to exprn are evaluated. That is, the 
expressions expr1 to exprn can reference identifiers that are bound by one of 
the patterns pattern1, . . . , patternn, and expect them to have the same value
as in expr, the body of the let rec construct.
The recursive definition is guaranteed to behave as described above if the 
expressions expr1 to exprn are function definitions (fun . . . or
function . . .),
and the patterns pattern1 . . . patternn are just value names, as in:
       let rec name1 = fun . . . and . . . and namen = fun . . . in expr
This defines name1 . . . namen as mutually recursive functions local to expr.

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