Re: string/char vector type equivalence

Phil Clayton <[email protected]> Mon, 04 Feb 2013 19:29:54 +0000
Newsgroups gmane.comp.lang.ml.mlton.devel
Message-ID <[email protected]>
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.


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan