[MLton-devel] new basis library

Stephen Weeks MLton@mlton.org
Thu, 25 Jul 2002 09:56:29 -0700


> Naively, I want to do the following:
> type string = char vector (* in primitive.sml *)
> functor MonoVector(type elem): MONO_VECTOR_EXTRA =
>    struct
>       open Vector
>       type elem = elem
>       type vector = elem vector
>    end
> structure CharVector = MonoVector(type elem = char)
> structure String =
>    struct
>       open CharVector
>       type char = elem (* = char *)
>       type string = vector (* = char vector *)
>       ... String operations ...
>    end

This is very similar to what we do now, except that it defines String
in terms of CharVector instead of CharVector in terms of string.  I
have no problem with going this way.

> signature BASIS = 
>   sig
>     ...
>     structure CharVector: MONO_VECTOR
>     sharing type elem = char
>     structure String:> STRING
>     sharing type string = CharVector.vector
>     type string = String.string
>   end

(corrections)

signature BASIS = 
   sig
      type char
      type string 
      structure CharVector: MONO_VECTOR
      sharing type CharVector.elem = char
      sharing type CharVector.vector = string
      structure String: STRING
      sharing type String.char = char
      sharing type String.string = string
   end

> > strings and char vectors are different types, but have the same
> > representation, so coercion between them is constant time (or even
> > free if the backend/codegen do the right thing).
> 
> Is this essential?  Would it be very difficult to treat strings and
> char vectors as equal types?

I don't think so.  It is important to distinguish between arrays and
vectors because they have different equality properties.  But I don't
see any distinction between strings and char vectors.  You could try
removing string from PRIM_TYCONS and adding "val string = vector char"
to atoms/type-ops.fun and see what happens.  It looks like it will
cause a few problems, the most difficult being that constants types
are no longer describable via a tycon, but nothing too bad.

This sounds worth trying to me.


-------------------------------------------------------
This sf.net email is sponsored by: Jabber - The world's fastest growing 
real-time communications platform! Don't just IM. Build it in! 
http://www.jabber.com/osdn/xim
_______________________________________________
MLton-devel mailing list
MLton-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mlton-devel