Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* Let rec trouble
@ 1998-07-25 19:06 Christopher Oliver
  1998-07-27 18:30 ` Pierre Weis
  0 siblings, 1 reply; 3+ messages in thread
From: Christopher Oliver @ 1998-07-25 19:06 UTC (permalink / raw)
  To: caml-list

I'm having trouble with the syntax of let rec.  Consider the following
program for computing Van der Waerden's bound:

  open Num
  open Nat
  open Big_int
  open Ratio

  let rec n k l =
    let rec m i =
      if i =/ Int 0 then
        Int 1 else
        Int 2
          */ (m (pred_num i))
          */ (n (k **/ (m (pred_num i))) (pred_num l)) in
    if l =/ Int 2 then succ_num k else m k;;

  print_string (string_of_num (n (Int 3) (Int 3)));;

I would like to restrict the lexical scope of 'n' by replacing the first
double semicolon with 'in.'  I nest m precisely to capture k and l in m's
lexical environment.  Why is this use forbidden?  I.e. Why shouldn't I be
able to write:

  let rec n k l =
    let rec m i =
      if i =/ Int 0 then
        Int 1 else
        Int 2
          */ (m (pred_num i))
          */ (n (k **/ (m (pred_num i))) (pred_num l)) in
    if l =/ Int 2 then succ_num k else m k
  in
    print_string (string_of_num (n (Int 3) (Int 3)));;

I would prefer not to define a top level symbol, and this seems an
inconsistancy.  Am I missing something?

-- 
Christopher Oliver                     Traverse Internet
Systems Coordinator                    223 Grandview Pkwy, Suite 108
oliver@traverse.net                    Traverse City, Michigan, 49684
let magic f = fun x -> x and more_magic n f = fun x -> f ((n f) x);;





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1998-07-28 16:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <199807280014.CAA01029@pauillac.inria.fr>
1998-07-28  6:15 ` Let rec trouble Christopher Oliver
1998-07-25 19:06 Christopher Oliver
1998-07-27 18:30 ` Pierre Weis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox