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 VAA06176 for caml-red; Mon, 6 Nov 2000 21:06:21 +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 EAA08291 for ; Sun, 5 Nov 2000 04:08:00 +0100 (MET) Received: from mta5.snfc21.pbi.net (mta5.snfc21.pbi.net [206.13.28.241]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id eA537x911472 for ; Sun, 5 Nov 2000 04:07:59 +0100 (MET) Received: from checkerlap.d6.com ([64.160.52.206]) by mta5.snfc21.pbi.net (Sun Internet Mail Server sims.3.5.2000.01.05.12.18.p9) with ESMTP id <0G3J00CDC7838H@mta5.snfc21.pbi.net> for caml-list@inria.fr; Sat, 4 Nov 2000 19:04:52 -0800 (PST) Date: Sat, 04 Nov 2000 19:06:35 -0800 From: Chris Hecker Subject: fixed length arrays as types X-Sender: def6@shell16.ba.best.com To: caml-list@inria.fr Message-id: <4.3.2.7.2.20001104165041.00b3e370@shell16.ba.best.com> MIME-version: 1.0 X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Content-type: text/plain; charset="us-ascii" 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. 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. Chris