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 SAA27433 for caml-red; Wed, 8 Nov 2000 18:17:20 +0100 (MET) 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 OAA23403 for ; Tue, 7 Nov 2000 14:21:37 +0100 (MET) Received: from dpt-info.u-strasbg.fr (dpt-info.u-strasbg.fr [130.79.6.1]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id eA7DLWv17136 for ; Tue, 7 Nov 2000 14:21:32 +0100 (MET) Received: from lambda.u-strasbg.fr (lambda.u-strasbg.fr [130.79.90.63]) by dpt-info.u-strasbg.fr (8.9.3/8.9.3) with ESMTP id PAA22190; Tue, 7 Nov 2000 15:20:27 +0100 Received: from luther by lambda.u-strasbg.fr with local (Exim 3.16 #1 (Debian)) id 13t8ne-0008Pb-00; Tue, 07 Nov 2000 14:28:30 +0100 Date: Tue, 7 Nov 2000 14:28:30 +0100 To: Chris Hecker Cc: caml-list@inria.fr Subject: Re: fixed length arrays as types Message-ID: <20001107142830.B30034@lambda.u-strasbg.fr> References: <4.3.2.7.2.20001104165041.00b3e370@shell16.ba.best.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <4.3.2.7.2.20001104165041.00b3e370@shell16.ba.best.com>; from checker@d6.com on Sat, Nov 04, 2000 at 07:06:35PM -0800 From: Sven LUTHER Sender: weis@pauillac.inria.fr On Sat, Nov 04, 2000 at 07:06:35PM -0800, Chris Hecker wrote: > > 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. > > Something like this C++: > > template class vector { float a[N]; }; > vector<3> add( vector<3> v1, vector<3> v2 ); > > vector<3> v3 = add(vector<3>(),vector<3>()); // works > vector<3> v4 = add(vector<5>(),vector<3>()); // type error (note v<5> > > I guess the higher level question is whether scalar constants can be part of the type signature like they can be in C++. Or, the related but different question is whether there's a way to differentiate between "float a[]" (or "float *a"), the variable length array type, and "float a[3]", a fixed length array type, which C++ doesn't do, but it lets you wrap the ideas in template classes which do allow you to represent this to the type system. Try using lists, Friendly, Sven Luther