Re: string/char vector type equivalence

Matthew Fluet <[email protected]> Tue, 5 Feb 2013 09:31:56 -0500
Newsgroups gmane.comp.lang.ml.mlton.devel
Message-ID <CAMrhFL4jODSmigVvL3do_EF89sfgx4F6pL8u=PvVbAH6UHsV+g@mail.gmail.com>
On Mon, Feb 4, 2013 at 2:29 PM, Phil Clayton <[email protected]>wrote:

> On 04/02/13 03:36, Christopher Cramer wrote:
> > This compiles in MLton without error:
> >
> >       val foo: char vector = "foo"
> >       val bar: string = "bar"
> >       val baz: string = vector [#"b", #"a", #"z"]
> >       val _ = Vector.length foo
> >       val _ = size foo
> >       val _ = Vector.length bar
> >       val _ = size bar
> >       val _ = Vector.length baz
> >       val _ = size baz
> >       val _ = foo ^ bar ^ baz
> >
> > Not an earth-shattering discovery, but it does make MLton.CharVector
> > redundant...
>
> The FAQ (http://www.mlton.org/FAQ) even states:
>
>    Does MLton treat monomorphic arrays and vectors specially?
>
>    MLton implements monomorphic arrays and vectors (e.g. BoolArray,
>    Word8Vector) exactly as instantiations of their polymorphic
>    counterpart (e.g. bool array, Word8.word vector).
>
> so MLton.CharVector does seem superfluous.
>
>
> > The same sort of thing, with ints rather than chars, does not compile:
> >
> >       val foo: IntVector.vector = vector [1, 2, 3]
> >
> >       Error: intvector.sml 1.5.
> >         Pattern and expression disagree.
> >           pattern:    [IntVector.vector]
> >           expression: [int vector]
> >           in: (foo): IntVector.vector = vector [1, 2, 3]
> >       compilation aborted: parseAndElaborate reported errors
>
> This surprises me.  Given what is said in the FAQ, I would expect
> similar examples like
>
>    val a : BoolArray.array =
>      Array.fromList [true, false] : bool Array.array;
>
> to work.
>
> However, not allowing the above has the advantage that code will be more
> portable.


Agreed.  And, I would actually argue that the first example should have a
type error as well.  I think that the reason that it doesn't is to support
string constants, but I couldn't quickly see where the necessary type
equalities were established in the Basis Library implementation and the
type checker.

------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb

_______________________________________________
MLton-devel mailing list
[email protected]; [email protected]
https://lists.sourceforge.net/lists/listinfo/mlton-devel