Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: David Monniaux <David.Monniaux@ens-lyon.fr>
To: Christian Lindig <lindig@ips.cs.tu-bs.de>
Cc: caml-list@inria.fr
Subject: Re: arity of type constructors
Date: Thu, 8 May 1997 22:15:23 +0200 (MET DST)	[thread overview]
Message-ID: <Pine.GSO.3.95.970508220638.26708C-100000@terreaux> (raw)
In-Reply-To: <199705071316.PAA14881@infbsst5.ips.cs.tu-bs.de>

[en francais: pourquoi un constructeur qui prend une paire comme argument
n'est pas la meme chose qu'un constructeur qui prend deux arguments]

On Wed, 7 May 1997, Christian Lindig wrote:

> 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:
It's 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?

The problem is exactly there.
If you declare type t = T of int*int, it declares a type t whose only
constructor takes two parameters, of respective types int and int, not a
constructor that takes one paramete of type int*int. Thus it can't be
applied to a pair.

That is reflected in the way memory objects are handled. A constructor
that takes a pair as an argument will have the following layout:

T -> pair [ int
          [ int

if it has two arguments, the layout is the following:

T [ int
  [ int

Using a pair adds one level of indirection.

For what you want to work, just do the following:
        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;;
- : t = T (3, 4)

Cheers.

"Le MIM est un magistère." (private joke)
Computer science student at ENS, Lyon, France
http://www.ens-lyon.fr/~dmonniau





  reply	other threads:[~1997-05-10 13:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-05-07 13:16 Christian Lindig
1997-05-08 20:15 ` David Monniaux [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.GSO.3.95.970508220638.26708C-100000@terreaux \
    --to=david.monniaux@ens-lyon.fr \
    --cc=caml-list@inria.fr \
    --cc=lindig@ips.cs.tu-bs.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox