Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* arity of type constructors
@ 1997-05-07 13:16 Christian Lindig
  1997-05-08 20:15 ` David Monniaux
  1997-05-09  5:57 ` Michel Quercia
  0 siblings, 2 replies; 7+ messages in thread
From: Christian Lindig @ 1997-05-07 13:16 UTC (permalink / raw)
  To: caml-list


Dear Caml-Enthusiasts,

the following example of applying arguments to a new type constructor
was surprising for me. I'm wondering if it's a bug or a feature:

        Objective Caml version 1.05
        # type t = T of int * int;;
        type t = | T of int * int
        # let x = (3,4);;
        val x : int * int = 3, 4
        # T x;;
        The constructor T expects 2 argument(s), but is here applied 
        to 1 argument(s)
        # T (3,4);;
        - : t = T (3, 4)

Applying T to x does not work, but applying it to (3,4) does. Why is
the pair (3,4) counted as 2 arguments?


Christian

[sorry, no french version - will visit Paris in summer as a compensation :-)]
------------------------------------------------------------------------------
 Christian Lindig  				       lindig@ips.cs.tu-bs.de
 TU Braunschweig				       fon   +49 531 391 7465
 Institut fuer Programmiersprachen		       fax   +49 531 391 8140
 D-38106 Braunschweig             		       http://www.cs.tu-bs.de







^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re:  arity of type constructors
@ 1997-05-09 11:53 Damien Doligez
  0 siblings, 0 replies; 7+ messages in thread
From: Damien Doligez @ 1997-05-09 11:53 UTC (permalink / raw)
  To: caml-list

>Applying T to x does not work, but applying it to (3,4) does. Why is
>the pair (3,4) counted as 2 arguments?

Constructors have an arity.  Here, T expects two arguments.  When you
write T(3,4), you're not applying T to a pair, but applying T to two
arguments, 3 and 4.  It happens that the syntax looks like a pair, but
this is more a misfeature of the syntax than anything else.

The alternative is to make all constructors take one argument, and use
a pair as argument when you want two arguments.  This approach is
harder to implement and it makes it possible to write horribly
obfuscated code.  Moreover, the pair has to be something special.  In
the current system, the pair is just another binary constructor.

We have tried both approaches in Caml Light, and I really think the
current one is the right one.


En Francais:

Les constructeurs ont une arite.  Quand on ecrit T(3,4), on n'applique
pas T a la paire (3,4), comme la syntaxe pourrait le faire croire,
mais on applique T a deux arguments, 3 et 4.

-- Damien





^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: arity of type constructors
@ 1997-05-12  7:08 Hubert Canon
  0 siblings, 0 replies; 7+ messages in thread
From: Hubert Canon @ 1997-05-12  7:08 UTC (permalink / raw)
  To: caml-list

> # type t = T of int * int;;
> type t = | T of int * int
> # T(3,4);;

I do not understand why we don't use another syntax for constructors :

If we had something like :
# T 3 4;;
- : t = (T 3 4)

it would be less confusing.

-- 
Hubert Canon





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1997-05-22  7:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-05-07 13:16 arity of type constructors Christian Lindig
1997-05-08 20:15 ` David Monniaux
1997-05-21 10:50   ` John Harrison
1997-05-21 18:46     ` Xavier Leroy
1997-05-09  5:57 ` Michel Quercia
1997-05-09 11:53 Damien Doligez
1997-05-12  7:08 Hubert Canon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox