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 SAA23220 for caml-red; Wed, 8 Nov 2000 18:38:00 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA05054 for ; Wed, 8 Nov 2000 10:53:16 +0100 (MET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id eA89rC512369; Wed, 8 Nov 2000 10:53:12 +0100 (MET) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA12926; Wed, 8 Nov 2000 10:53:12 +0100 (MET) Message-ID: <20001108105312.57768@pauillac.inria.fr> Date: Wed, 8 Nov 2000 10:53:12 +0100 From: Xavier Leroy To: Chris Hecker , caml-list@inria.fr Subject: Re: fixed length arrays as types References: <4.3.2.7.2.20001104165041.00b3e370@shell16.ba.best.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89.1 In-Reply-To: <4.3.2.7.2.20001104165041.00b3e370@shell16.ba.best.com>; from Chris Hecker on Sat, Nov 04, 2000 at 07:06:35PM -0800 Sender: weis@pauillac.inria.fr > Is there any way to do this: > type vector3 = [| float; float; float |]; > Basically, I want an array of a given length to be a given type, so > I can use the type system to check add_vector3 rather than throwing > if the arrays don't match. I know I can make records {x:float, > y:float} but I'd like it to be parameterizable at compile time. I understand why you'd like to do this, but having array sizes in the types, along with sufficient polymorphism over array sizes (so that a fixed-size array can be viewed as a variable-size array whenever needed), all in a type inference setting, would require a fairly complex type system. (See for instance Pfenning and Xi's Dependent ML.) To me, having array sizes in the array types is mostly a left-over from languages where the compiler needs to treat static or stack-allocated arrays differently than dynamically-allocated arrays. My feeling is that when all arrays are dynamically allocated, it's more natural and a whole lot simpler to never reflect array sizes in array types. As a case in point, the evolution from C++ to Java follows this path. - Xavier Leroy