From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA23436 for caml-redistribution; Sat, 10 May 1997 15:57:19 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id WAA26610 for ; Thu, 8 May 1997 22:15:31 +0200 (MET DST) Received: from cri.ens-lyon.fr (cri.ens-lyon.fr [140.77.1.32]) by nez-perce.inria.fr (8.8.5/8.7.3) with ESMTP id WAA10835 for ; Thu, 8 May 1997 22:15:29 +0200 (MET DST) Received: from terreaux (terreaux [140.77.191.109]) by cri.ens-lyon.fr (8.8.5/8.8.1) with ESMTP id WAA10722; Thu, 8 May 1997 22:15:26 +0200 (MET DST) Date: Thu, 8 May 1997 22:15:23 +0200 (MET DST) From: David Monniaux X-Sender: dmonniau@terreaux To: Christian Lindig cc: caml-list@inria.fr Subject: Re: arity of type constructors In-Reply-To: <199705071316.PAA14881@infbsst5.ips.cs.tu-bs.de> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT Sender: weis [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