From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id B12EFBC0B for ; Wed, 3 Jan 2007 09:46:12 +0100 (CET) Received: from postar.fmf.uni-lj.si (vega.fmf.uni-lj.si [193.2.67.45]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l038kBnN004684 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 3 Jan 2007 09:46:12 +0100 Received: from localhost (unknown [192.168.5.1]) by postar.fmf.uni-lj.si (Postfix) with ESMTP id 7C60DE6817; Wed, 3 Jan 2007 09:46:11 +0100 (CET) X-Virus-Scanned: amavisd-new at spam.fmf.uni-lj.si Received: from postar.fmf.uni-lj.si ([192.168.5.5]) by localhost (spam.fmf.uni-lj.si [192.168.5.1]) (amavisd-new, port 10024) with ESMTP id aNAyNziJkDDS; Wed, 3 Jan 2007 09:55:48 +0100 (CET) Received: from [193.2.67.88] (unknown [193.2.67.88]) by postar.fmf.uni-lj.si (Postfix) with ESMTP id 4559DE67B2; Wed, 3 Jan 2007 09:46:11 +0100 (CET) Message-ID: <459B6D53.7050109@fmf.uni-lj.si> Date: Wed, 03 Jan 2007 09:46:11 +0100 From: Andrej Bauer Reply-To: Andrej.Bauer@andrej.com User-Agent: Icedove 1.5.0.8 (X11/20061129) MIME-Version: 1.0 To: Jon Harrop Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Lazy.force References: <200701022221.11975.jon@ffconsultancy.com> In-Reply-To: <200701022221.11975.jon@ffconsultancy.com> Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 459B6D53.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; andrej:01 andrej:01 checker:01 typechecker:01 compiler:01 wrote:01 rec:01 rec:01 caml-list:01 int:01 int:01 lazy:02 lazy:02 expression:02 expression:02 Jon Harrop wrote: > Could the type checker automatically insert Lazy.force whenever a lazy > expression is used as an eager expression? Consider: let rec repeat n x = if n = 0 then [] else x :: (repeat (n-1) x) let rec sum = function [] -> 0 | x::xs -> x + sum xs let cow = sum (repeat 1000 (lazy 3)) The typechecker will determine that repeat : int -> 'a -> 'a list sum : int list -> int In the definition of cow it will see that sum, which expects int list, is applied to int lazy_t list. Where and how should the compiler insert Lazy.force in this example? Note that it cannot insert anything in the definition of sum, because later on it might see let chicken = sum [1;2;3;4] Best regards, Andrej