caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Shishir Ramam <sramam@gmail.com>
To: caml-list@inria.fr
Subject: [Caml-list] trouble w/ recursive let definitions.
Date: Sun, 15 Aug 2004 10:05:15 -0700	[thread overview]
Message-ID: <83f599680408151005288b6bf9@mail.gmail.com> (raw)

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


             reply	other threads:[~2004-08-15 17:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-15 17:05 Shishir Ramam [this message]
2004-08-15 21:29 ` Brian Hurt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83f599680408151005288b6bf9@mail.gmail.com \
    --to=sramam@gmail.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).