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 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 9ACD3BBAF for ; Thu, 8 Oct 2009 14:42:14 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AokBAG97zUrZSMDji2dsb2JhbACBUpkuAQEBCgsKBxEFvhOEKgSBWA X-IronPort-AV: E=Sophos;i="4.44,525,1249250400"; d="scan'208";a="37845674" Received: from fmmailgate02.web.de ([217.72.192.227]) by mail1-smtp-roc.national.inria.fr with ESMTP; 08 Oct 2009 14:42:14 +0200 Received: from smtp07.web.de (fmsmtp07.dlan.cinetic.de [172.20.5.215]) by fmmailgate02.web.de (Postfix) with ESMTP id 7C42312B297DB; Thu, 8 Oct 2009 14:37:08 +0200 (CEST) Received: from [95.208.117.111] (helo=frosties.localdomain) by smtp07.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #314) id 1MvsF2-00063J-00; Thu, 08 Oct 2009 14:37:08 +0200 Received: from mrvn by frosties.localdomain with local (Exim 4.69) (envelope-from ) id 1MvsF1-0001NK-SI; Thu, 08 Oct 2009 14:37:07 +0200 From: Goswin von Brederlow To: "David Allsopp" Cc: "'Jon Harrop'" , Subject: Re: [Caml-list] Constructors are not functions References: <4ACB319A.1080608@wanadoo.fr> <003901ca4682$d47f8460$7d7e8d20$@metastack.com> <200910061415.48065.jon@ffconsultancy.com> <005501ca468d$dc9b51a0$95d1f4e0$@metastack.com> Date: Thu, 08 Oct 2009 14:37:07 +0200 In-Reply-To: <005501ca468d$dc9b51a0$95d1f4e0$@metastack.com> (David Allsopp's message of "Tue, 6 Oct 2009 15:04:02 +0100") Message-ID: <87ljjmxdsc.fsf@frosties.localdomain> User-Agent: Gnus/5.110006 (No Gnus v0.6) XEmacs/21.4.22 (linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: goswin-v-b@web.de X-Sender: goswin-v-b@web.de X-Provags-ID: V01U2FsdGVkX1+gWoZ2rKNmeUbJurHaHD8+DyRcCyQzSo29Jq3P BXmFuck6u7rKxkIR/r2tPZ59T93LUy/BxmBAbOyHYMrMX9Lqh8 0Fhnm3qzU= X-Spam: no; 0.00; constructors:01 simulate:01 ocaml:01 camlp:01 foo:01 constructors:01 camlp:01 cmi:01 foo:01 val:01 curried:01 mfg:98 sml:01 unbound:01 wrote:01 "David Allsopp" writes: > Jon Harrop wrote: >> David Allsopp wrote: >> > I think it would be possible to simulate the SML behaviour in OCaml >> > using camlp4 (if you assume that for [type foo = Bar of int] that future >> > unbound references to [bar] are interpreted as [fun x -> bar x] instead of an >> > error) >> >> Only if you turned multi-argument type constructors into single- >> argument ones >> taking a tuple, i.e. type definitions like: >> >> type t = Bar of int * int >> >> must become: >> >> type t = Bar of (int * int) > > That's not the case at all - there'd be no reason not to interpret [bar] as [fun x y -> Bar(x, y)] for [Bar of int * int]. What would be hairy in camlp4 would be having to read .cmi files to deal with types defined outside your source file, but that's still not impossible... > > > David Then what about type t1 = Bar of int * int type t2 = Foo of (int * int) If you treat constructors as functions taking one argument then t1: int * int -> t1 t2: int * int -> t2 But: # let x = (1,2);; val x : int * int = (1, 2) # Foo(x);; - : t2 = Foo (1, 2) # Bar(x);; Error: The constructor Bar expects 2 argument(s), but is here applied to 1 argument(s) As functions "Bar" would have to deconstruct the tuple while "Foo" uses it directly. And I would rather have curried constructors as in "Bar 1 : int -> t1". The difference between t1 and t2 gets lost. I actually hate that you can write "Bar(1,2)" and "Foo(1,2)" Same problem there. It is unclear if you pass 2 arguments or a tuple. This should really be t1: int -> int -> t1 t2: int * int -> t2 fun x y -> Bar x y fun (x,y) -> Foo (x,y) MfG Goswin