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=1.0 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id E19AEBC6C for ; Sat, 24 Nov 2007 19:48:27 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAHIASEdC+VLrnmdsb2JhbACPPgEBAQEHBAYp X-IronPort-AV: E=Sophos;i="4.21,461,1188770400"; d="scan'208";a="19636789" Received: from wx-out-0506.google.com ([66.249.82.235]) by mail4-smtp-sop.national.inria.fr with ESMTP; 24 Nov 2007 19:48:26 +0100 Received: by wx-out-0506.google.com with SMTP id h27so175275wxd for ; Sat, 24 Nov 2007 10:48:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:reply-to:to:subject:date:user-agent:cc:references:in-reply-to:content-type:content-transfer-encoding:content-disposition:message-id; bh=vpb4nLUXeTY9DDQ4+lzCwz67QXh4Igj56WZbOlM4ELc=; b=uuC6nA57axunIrG9IjmAta3xPrcu+waLIkVGSrWgAkIvlsP8PwB5MP+OFzv5KV5EyNkJ6fnogLtTy+Lk8ZdweJ8TsMy7YNlYovPnpXp/9GOVkaOGgzfkJY4Q1l2DS005a1ruqWmB0yqE1AK6VfPh33+OZll0NBQPiWp5pGLKA5Y= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=received:from:reply-to:to:subject:date:user-agent:cc:references:in-reply-to:content-type:content-transfer-encoding:content-disposition:message-id; b=HZT6soIUVwwqZxg6D9d0QuFbToHpdnOp3H9ksTW7lBVzbkGgLnaVD6UNShBjRsffIkDtrh57zS2bmu40ie4nfOxs0Y4poyCt9mEQwDUpR5iLM1Yr+sa4DGWfTu4RQwrMcJwN2Y0uAtdTrk/AXqfMVmWbB1czMsPiAxJTdkDvc7s= Received: by 10.70.40.3 with SMTP id n3mr1304730wxn.1195930105499; Sat, 24 Nov 2007 10:48:25 -0800 (PST) Received: from tama-chan ( [24.99.180.210]) by mx.google.com with ESMTPS id h37sm148173wxd.2007.11.24.10.48.24 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 24 Nov 2007 10:48:24 -0800 (PST) From: Peng Zang Reply-To: peng.zang@gmail.com To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] weird behavior with built-in ignore function (a bug?) Date: Sat, 24 Nov 2007 13:48:18 -0500 User-Agent: KMail/1.9.7 Cc: Julien Moutinho References: <200711231109.47460.peng.zang@gmail.com> <20071124003110.GA32596@localhost> In-Reply-To: <20071124003110.GA32596@localhost> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200711241348.22594.peng.zang@gmail.com> X-Spam: no; 0.00; bug:01 hash:01 bug:01 externally:01 compiler:01 val:01 foo:01 val:01 foo:01 transforming:01 ocamlc:01 ocamlc:01 pervasives:01 ocaml:01 bool:01 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Ahhh... it's good to know this is a bug and that it has been fixed. I think for the interim I will simply define my own ignore function. It also bothers me that even in the fixed version ignore does not equal itself. I also don't see why ignore is even defined externally. Doesn't the compiler optimize ignore calls away? Peng On Friday 23 November 2007 07:31:11 pm Julien Moutinho wrote: > On Fri, Nov 23, 2007 at 11:09:44AM -0500, Peng Zang wrote: > > I have run into what appears to be very odd behavior with the built-in > > function "ignore". I will demonstrate below. It's a little > > complicated, but it's the smallest testcase I could make it: > > > > # type 'a fruit = 'a > > and 'b veggie = 'b > > and ('a,'b) kitchen = { source : ; > > sink : 'b veggie>; } > > ;; > > > > # let bar sink x = sink#trans x;; > > val bar : < trans : 'a -> 'b; .. > -> 'a -> 'b = > > > > # let foo src snk = > > let m = { source = src; sink = snk } in > > ignore (bar m.sink m.source#make); > > ignore (bar m.sink m.source#make); > > () > > ;; > > val foo : < make : 'a fruit > -> < trans : 'a fruit -> '_b veggie > -> > > unit = > > > > > > Basically, we have two objects. One is producing fruits (source) and > > the other is transforming them into vegetables (sink). Note the > > inferred typesig of foo, it thinks the trans method returntype is '_b > > veggie. This seems strange. I think it should return a fully > > polymorphic 'b veggie. > > [..] > > AFAICS it has been fixed in the release310 branch: > http://caml.inria.fr/mantis/view.php?id=4350 > > % git checkout release310 > Switched to branch "release310" > % make ocamlc > [...] > % ./ocamlc -i peng__071123.ml > type 'a fruit = 'a > and 'a veggie = 'a > and ('a, 'b) kitchen = { > source : < make : 'a fruit >; > sink : < trans : 'a fruit -> 'b veggie >; > } > val bar : < trans : 'a -> 'b; .. > -> 'a -> 'b > val foo : < make : 'a fruit > -> < trans : 'a fruit -> 'b veggie > -> unit > > % git-log --grep='PR#4350' > commit 4240263b7cbe15e87cc24e797aac6917eacb9f71 > Author: garrigue > Date: Mon Oct 29 04:40:34 2007 +0000 > > PR#4350 > % git-revert 4240263b > % make ocamlc > % ./ocamlc -i peng__071123.ml > type 'a fruit = 'a > and 'a veggie = 'a > and ('a, 'b) kitchen = { > source : < make : 'a fruit >; > sink : < trans : 'a fruit -> 'b veggie >; > } > val bar : < trans : 'a -> 'b; .. > -> 'a -> 'b > val foo : < make : 'a fruit > -> < trans : 'a fruit -> '_b veggie > -> unit > > % git-reset --hard 'HEAD^' > > > To verify. I now re-define foo without the use of ignore: > > > > # let foo src snk = > > let m = { source = src; sink = snk } in > > let _ = bar m.sink m.source#make in > > let _ = bar m.sink m.source#make in > > ();; > > val foo : < make : 'a fruit > -> < trans : 'a fruit -> 'b veggie > -> > > unit = > > > > This time the return type for trans is fully polymorphic! Using > > ignore as in the first case broke something. > > > > For a strange turn, I make my own ignore function and redefine foo > > with that: > > > > # let myignore x = ();; > > val myignore : 'a -> unit = > > # let foo src snk = > > let m = { source = src; sink = snk } in > > myignore (bar m.sink m.source#make); > > myignore (bar m.sink m.source#make); > > () > > ;; > > val foo : < make : 'a fruit > -> < trans : 'a fruit -> 'b veggie > -> > > unit = > > > > This also yields returns a fully polymorphic veggie! So it's > > something unique to the build-in ignore function? > > Perhaps the fact that Pervasives.ignore is defined like that: > > external ignore : 'a -> unit = "%ignore" > > BTW be aware that: > % ocaml > Objective Caml version 3.10.1+dev2 (2007-11-20) > > # ignore == ignore;; > - : bool = false > # let ignore _ = ();; > val ignore : 'a -> unit = > # ignore == ignore;; > - : bool = true > > > So now my puzzling question: what is going on? What is wrong with the > > build-in ignore function that would make it mess up the return type of > > the trans method? Is this a bug? > > > > Thanks, > > > > Peng > > > > PS. I'm using OCaml 3.09.3, haven't tried with 3.10 > > HTH, > Julien. > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.7 (GNU/Linux) iD8DBQFHSHH2fIRcEFL/JewRAmZUAKCn7EQXCVEGdSNaxSUu7XYGwQ2tuQCcChv1 WK/7GzYGRj5Vs4WGaULXTnE= =gE5n -----END PGP SIGNATURE-----