Thread: Re: Re: Re: Re: "ocaml_beginners"::[] Am I overtyping?
Re: Re: Re: Re:
"ocaml_beginners"::[] Am I
overtyping?
United States
2007-10-12 12:04:20
From: "William D. Neumann" < wneumann%40cs.unm.edu">wneumanncs.unm.edu>
> Of course this is still behaving in the exact same way, it's just that here
> we get a bit of extra type naming information passed into the type
> inferencer so that it can report back the name point in stead of the
> equivalent vector or { x : float; y : float; z : float; }. They're still
> the same thing and can be interchanged willy nilly:
Yeah. After further testing this doesn't do what I want. "willy
nilly" is a pretty good description. I was hoping something like:
let pv_plus_pv (i:'a) (j:'a) : 'a =
{x=i.x +. j.x;y=i.y +. j.y;z=i.z +. j.z}
would throw an error if 'i' was a point and 'j' was a vector. Or that
specifying a return value of 'point' or 'vector' wouldn't implicitly
cast. This seems more like an alias than a different type.
Re: Re: Re: Re:
"ocaml_beginners"::[] Am I
overtyping?
United States
2007-10-12 12:25:13
On Fri, 12 Oct 2007 12:04:20 -0500 (CDT), olsongt wrote
> This seems more like an alias than a different type.
That's because that's all it is, an alias. If you want them to actually be
distinct types, then you'll need to use something like variants, records
with distinct field names, abstract types inside modules, etc.