From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id CCF3FBDD8 for ; Fri, 26 Aug 2005 12:57:07 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j7QAv7jx003212 for ; Fri, 26 Aug 2005 12:57:07 +0200 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 MAA26581 for ; Fri, 26 Aug 2005 12:57:06 +0200 (MET DST) Received: from rigel.cs.pdx.edu (rigel.cs.pdx.edu [131.252.208.59]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j7QAv48s003201 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Fri, 26 Aug 2005 12:57:06 +0200 Received: from [192.168.0.101] (host-245-239.resnet.pdx.edu [131.252.245.239]) by rigel.cs.pdx.edu (8.13.1/8.13.1) with ESMTP id j7QAulcE004308; Fri, 26 Aug 2005 03:56:50 -0700 (PDT) Message-ID: <430EF56A.1030703@cs.pdx.edu> Date: Fri, 26 Aug 2005 03:56:42 -0700 From: Marius Nita User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jonathan Roewen Cc: caml-list@inria.fr Subject: Re: [Caml-list] lazy lists References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new X-Miltered: at concorde with ID 430EF583.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 430EF580.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 lazy:01 ocaml:01 lazy:01 haskell:01 ocaml:01 haskell:01 haskell's:01 semantics:01 semantics:01 ocaml's:01 wrote:01 structures:01 define:01 imperative:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Jonathan Roewen wrote: > Hi, > > Is the underlying implementation of the builtin lists in OCaml lazy? > If not, is performance the reason for them not being lazy? I think > lazy lists are a very strong point of Haskell, and am wondering if > there's a lazy list implementation with all the standard list > operations in the case that lists aren't lazy in OCaml. > > Also, if they aren't, can someone give me some insight into the > reasons INRIA chose not to? It's not just a question of the "underlying implementation." OCaml and Haskell use the same list definition: type 'a list = Cons of 'a * 'a list | Nil but in Haskell it is lazy due to Haskell's lazy evaluation semantics. OCaml has a strict evaluation semantics, so its lists, as defined above, are strict. If OCaml had chosen to implement lists lazily "behind the scenes," this would be easily observable (and very counter-intuitive!) due to OCaml's imperative features: let f _ = 5 in f [print_string "calling f\n"] would produce no output. The good news is that you can define your own lazy data structures pretty easily. OCaml offers the Lazy module, which makes working with lazy suspensions easier. marius