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=2.8 required=5.0 tests=AWL,DNS_FROM_RFC_POST, SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 2ABBDBBAF for ; Tue, 6 Oct 2009 14:19:59 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao8BAJLSykrRVdK2kGdsb2JhbACRO4h9PwEBAQEJCQwHEwOnE4E7jxkBAwMFhCUE X-IronPort-AV: E=Sophos;i="4.44,513,1249250400"; d="scan'208";a="34339056" Received: from mail-yx0-f182.google.com ([209.85.210.182]) by mail2-smtp-roc.national.inria.fr with ESMTP; 06 Oct 2009 14:19:58 +0200 Received: by yxe12 with SMTP id 12so3913878yxe.1 for ; Tue, 06 Oct 2009 05:19:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=nqJbmGkET61CaJpxQ+ShT8DZmvSH5iO/bd24hVi2vw0=; b=MVSyusQgYsx6unbrWXaQJVomITZmDDNiZTcq5mv99C/vDlmXEJJ1Uy8Gxtath1DKmn P+H3VpbuCEFbY+ohSOBKYuJSAE+W2qc/6QSrqH12mO1RTSpZkZXrvrKjezgbrDxl1yT0 MpS+FZxqu2o8jQs55yJPpDR/6o7wnzs4lfCVI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=V2s6wc/TyhFi73FCj1ikQb28oRfLW8OYUVIrXAwVdxjrxd3SsFxGRiQXf3eUiOnMJA gh1EJI5mqqwIU2Xs+afDf+23hNohvZ1hS3lkCu/fwsabnflEiEXTixr0kyOuQgdqQEVf HESIsYhZg72PToCLL7C6xwpXIsM2603vlmI3Y= MIME-Version: 1.0 Received: by 10.101.33.8 with SMTP id l8mr1395304anj.167.1254831598096; Tue, 06 Oct 2009 05:19:58 -0700 (PDT) In-Reply-To: <4ACB319A.1080608@wanadoo.fr> References: <4ACB319A.1080608@wanadoo.fr> Date: Tue, 6 Oct 2009 14:19:58 +0200 Message-ID: <4d1b2df20910060519n920bccaud71c0d28f9ce5269@mail.gmail.com> Subject: Re: [Caml-list] Constructors are not functions From: Philippe Wang To: Chantal KELLER Cc: caml-list Content-Type: text/plain; charset=ISO-8859-1 X-Spam: no; 0.00; constructors:01 semantics:01 semantics:01 constructors:01 cheers:01 ocaml:01 foo:01 foo:01 foobar:01 foobar:01 2009:98 wrote:01 partial:01 partial:01 caml-list:01 Hello, I don't know the actual reason, but I guess it's simply a choice of semantics. It woud be weird to be able to deconstruct (Bar 42) while not be able to deconstruct (Bar) as it's not constructed. I mean we can write (match x with Bar y -> y). If partial construction were accepted we may like to write (match x with Bar -> x) but we couldn't because Bar is like a function then. With type t = A | B of int what would be the error warning for (match x with A -> 42 | B -> 43) ? Well, then I guess the reason is that it would be complicated to choose some sound enough semantics for partial application of constructors, since the solution of having to write (fun x -> Bar x) is much simpler. If someone has the actual historical explanation, I am also interested. Cheers, Philippe Wang On Tue, Oct 6, 2009 at 2:01 PM, Chantal KELLER wrote: > Dear Ocaml users, > > Is there a reason for constructors not to behave like functions? For > instance, one cannot make a partial application from a constructor: > > # type foo = | Bar of int;; > type foo = Bar of int > # let foobar = Bar in foobar 17;; > Error: The constructor Bar expects 1 argument(s), > but is applied here to 0 argument(s) > > Thanks, > -- > Chantal KELLER