From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA07284; Thu, 2 May 2002 15:15:05 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA07288 for ; Thu, 2 May 2002 15:15:04 +0200 (MET DST) Received: from smtp2.cswv.com (smtp2.cswv.com [4.17.129.20]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g42DF3D24750 for ; Thu, 2 May 2002 15:15:03 +0200 (MET DST) Received: from smtp2.cswv.com ([10.2.3.6]) by smtp2.cswv.com with Microsoft SMTPSVC(5.5.1877.197.19); Thu, 2 May 2002 09:14:57 -0400 Received: FROM exchange1.cswv.com BY smtp2.cswv.com ; Thu May 02 09:14:56 2002 -0400 Received: by exchange1.cswv.com with Internet Mail Service (5.5.2653.19) id ; Thu, 2 May 2002 09:15:13 -0400 Message-ID: From: "Krishnaswami, Neel" To: OCaml Mailing list Subject: Re: [Caml-list] Breaking out of iterative loops Date: Thu, 2 May 2002 09:15:08 -0400 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain; charset="iso-8859-1" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Markus Mottl [mailto:markus@oefai.at] wrote: > On Wed, 01 May 2002, John Prevost wrote: > > The drawback to allowing: > > > > let rec ones = 1 :: ones > > > > and such expressions is that when looking at the definition of, for > > example, 'a list and length, one would expect it to be > > guaranteed that length terminates. > > I second this. Does anybody here really benefit from such cyclic > structures? Somewhat to my surprise, I can answer yes: type expr = | Var of string | App of expr * expr | Fun of string * expr | Rec of string * string * expr and denot = Closure of string * expr * env and env = (string * denot) list let rec eval e r = match e with | Var v -> List.assoc v r | App(f, arg) -> let Closure(n, body, r') = eval f r in let v = eval arg r in eval body ((n, v) :: r') | Fun(n, body) -> Closure(n, body, r) | Rec(name, n, body) -> let rec c = Closure(n, body, r') and r' = (name, c) :: r in c Using cyclic structures means I don't have to dink around with mutable references and all the headaches they bring, and so it's very handy when prototyping. -- Neel Krishnaswami neelk@cswcasa.com ------------------- 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