From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 3BE897FD26 for ; Fri, 6 Nov 2015 11:31:16 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.20,251,1444687200"; d="scan'208";a="186369927" Received: from meleze.ens.fr (HELO [129.199.99.114]) ([129.199.99.114]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 06 Nov 2015 11:31:08 +0100 To: caml-list@inria.fr References: <0F7D3B1B3C4B894D824F5B822E3E5A172CE3E070@IRSMSX102.ger.corp.intel.com> From: Francois Berenger Message-ID: <563C816B.7020604@inria.fr> Date: Fri, 6 Nov 2015 11:31:07 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <0F7D3B1B3C4B894D824F5B822E3E5A172CE3E070@IRSMSX102.ger.corp.intel.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Caml-list] Newbie comment on constructor syntax On 11/06/2015 10:33 AM, Soegtrop, Michael wrote: > Dear Ocaml users, > > I just started to develop in OCaml, and must say it is smoother than expected. Although I did C/C++ for decades, I do less errors in Ocaml, both syntactically and in terms of if programs behave as expected. It appears to be much closer to human thinking than C/C++ and I already wonder how I could live without currying and type inference before. > > The one thing I find rather non intuitive is that variant constructors can take only one argument - or a tuple. Although I know it is wrong, I always write "Constr a b" instead of "Constr (a, b)". I know syntax is only a minor thing and mostly a matter of taste, but a large fraction of my syntax errors in new code are of this kind (when modifying code it is a bit different). Somehow I think this doesn't go together well with the function call syntax of OCaml. I guess deep in my brain a constructor is a function which takes arguments and returns an element of the type it constructs, so I guess I want to use the usual function call syntax. > > My question: Is there some syntax to give a constructor more than one argument which escaped me? Something like if I leave away the * in the definition I can use usual function call syntax in constructions and expressions? I would find this easier to read and to write, especially in matches or nested constructs. Does everybody use camlp4/p5/ppx to customize the syntax to his liking (as chapter 5 of the camlp4 manual suggests)? Or are there some long term advantages of this syntax I don't see as yet? A dummy suggestion, but maybe you will like it: let constr a b = Constr (a, b) > Best regards, > > Michael > > Intel Deutschland GmbH > Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany > Tel: +49 89 99 8853-0, www.intel.de > Managing Directors: Christin Eisenschmid, Christian Lamprechter > Chairperson of the Supervisory Board: Nicole Lau > Registered Office: Munich > Commercial Register: Amtsgericht Muenchen HRB 186928 > > -- Regards, Francois. "When in doubt, use more types"