Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Chris Hecker <checker@d6.com>, caml-list@inria.fr
Subject: Re: fixed length arrays as types
Date: Wed, 8 Nov 2000 10:53:12 +0100	[thread overview]
Message-ID: <20001108105312.57768@pauillac.inria.fr> (raw)
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

> 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



  parent reply	other threads:[~2000-11-08 17:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-11-05  3:06 Chris Hecker
2000-11-07  8:41 ` Judicael Courant
2000-11-07 13:28 ` Sven LUTHER
2000-11-07 17:00 ` Brian Rogoff
2000-11-08  9:53 ` Xavier Leroy [this message]
2000-11-08 17:20   ` Chris Hecker
2000-11-09  4:03     ` William Lee Irwin III
2000-11-09 21:53       ` Chris Hecker
2000-11-11 15:15   ` John Max Skaller

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=20001108105312.57768@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=checker@d6.com \
    /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