[MLton-devel] new basis library

Stephen Weeks MLton@mlton.org
Thu, 25 Jul 2002 10:10:46 -0700


> The only drawback I can think of is with signatures that reference
> explicit structures; take, for example, the PACK_WORD signature:
> 
> signature PACK_WORD = sig
> val bytesPerElem : int
> val isBigEndian : bool
> val subVec  : Word8Vector.vector * int -> LargeWord.word
> val subVecX : Word8Vector.vector * int -> LargeWord.word
> val subArr  : Word8Array.array * int -> LargeWord.word
> val subArrX : Word8Array.array * int -> LargeWord.word
> val update : Word8Array.array * int * LargeWord.word -> unit
> end

To me, this is an inconsistency in the spec.  I would think it should
be:

signature PACK_WORD =
   sig
      type array
      type vector
      type word
      val bytesPerElem: int
      val isBigEndian: bool
      val subVec : vector * int -> word
      val subVecX: vector * int -> word
      val subArr : array * int -> word
      val subArrX: array * int -> word
      val update: array * int * word -> unit
   end

Then we could do:

signature BASIS =
   sig
      structure LargeWord: WORD
      structure Pack32Big: PACK_WORD
      structure Word8Array: MONO_ARRAY
      structure Word8Vector: MONO_VECTOR
      sharing type Pack32Big.array = Word8Array.array
      sharing type Pack32Big.vector = Word8Vector.vector
      sharing type Pack32Big.word = LargeWord.word
   end
 
> These Word8Vector.vector, Word8Array.array, and LargeWord.word correspond
> to the (non-opaquely matched) structures in scope when PACK_WORD is
> defined.  As such, these types won't be equal to their opaquely matched
> counterparts in Basis.

In the meantime, whe can get what we need by forcing the opaque types
to match the toplevel types using where clauses.

signature BASIS =
   sig
      structure LargeWord: WORD
      structure Pack32Big: PACK_WORD
      structure Word8Array: MONO_ARRAY
      structure Word8Vector: MONO_VECTOR
   end
      where type LargeWord.word = LargeWord.word
      where type Word8Array.array = Word8Array.array
      where type Word8Vector.vector = Word8Vector.vector

This looks a lot uglier to me because it doesn't make it nearly as
obvious that Pack32Big.subVec returns a LargeWord.word.  Matthew, if
you agree, maybe you could point out the improved version of PACK_WORD
to Reppy in a continuation of your discussion.  I guess the general
principal is that every signature should be closed (hmm, I wonder who
uses that style :-) and that relationships should be expressed via
sharing (hmm, I wonder who uses that style :-).


-------------------------------------------------------
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