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.2 required=5.0 tests=AWL 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 49E23BC54 for ; Tue, 6 Oct 2009 17:51:01 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAMoDy0rVuiYS/2dsb2JhbADTSgqEIASBUw X-IronPort-AV: E=Sophos;i="4.44,513,1249250400"; d="scan'208";a="34363725" Received: from solaria.dimino.org ([213.186.38.18]) by mail2-smtp-roc.national.inria.fr with ESMTP; 06 Oct 2009 17:51:01 +0200 Received: from aurora (localhost.localdomain [127.0.0.1]) by solaria.dimino.org (Postfix) with ESMTP id BABD480048; Tue, 6 Oct 2009 17:51:00 +0200 (CEST) Received: by aurora (Postfix, from userid 500) id 4727016EF; Tue, 6 Oct 2009 17:51:00 +0200 (CEST) Subject: Re: [Caml-list] Constructors are not functions From: =?ISO-8859-1?Q?J=E9r=E9mie?= Dimino To: Chantal KELLER Cc: caml-list In-Reply-To: <4ACB319A.1080608@wanadoo.fr> References: <4ACB319A.1080608@wanadoo.fr> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Date: Tue, 06 Oct 2009 17:50:59 +0200 Message-Id: <1254844259.2737.22.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.26.3 (2.26.3-1.fc11) X-Spam: no; 0.00; constructors:01 0200,:01 ocaml:01 constructors:01 foo:01 foo:01 foobar:01 foobar:01 camlp:01 val:01 val:01 syntax:01 2009:98 wrote:01 partial:01 Le mardi 06 octobre 2009 =C3=A0 14:01 +0200, Chantal KELLER a =C3=A9crit : > Dear Ocaml users, >=20 > Is there a reason for constructors not to behave like functions? For > instance, one cannot make a partial application from a constructor: >=20 > # type foo =3D | Bar of int;; > type foo =3D Bar of int > # let foobar =3D Bar in foobar 17;; > Error: The constructor Bar expects 1 argument(s), > but is applied here to 0 argument(s) This does not answer the question, but you can have function generated automatically for constructors using camlp4. I wrote some time ago an extension which add a type-conv type processor "constructor", so you can write: type t =3D Foo of string | Bar of int * int with constructor and it automatically generates these two functions: val foo : string -> t val bar : int -> int -> t The extension is available here: http://darcs.ocamlcore.org/cgi-bin/darcsweb.cgi?r=3Dobus;a=3Dheadblob;f=3D/= syntax/pa_constructor.ml --=20 J=C3=A9r=C3=A9mie