[MLton] Word<N>

Stephen Weeks MLton@mlton.org
Mon, 14 Mar 2005 17:39:58 -0800


> I hope I am not missing something obvious but why is N > 1.  Why not implement
> Word1?  Binary arithmetic is universally useful... just now I was trying to
> write the code to compute a binary determinant of a binary matrix but alas
> Word1 is not there.  Maybe it was left out to keep it symmetric with the Int
> case when Int1 would not make much sence.  But word1 does...

There is no good reason why Word1 isn't there.  Until it is, if you're
willing to live without source-level constants (0w0, 0w1), it is easy
to implement yourself.

structure Word1: WORD =
   struct
      datatype word = W0 | W1

      val op + =
         fn (W0, W0) => W0
          | (W0, W1) => W1
          | (W1, W0) => W1
          | (W1, W1) => W0

      ...
   end

Or, you could implement it much as we implement the other unusual word
sizes, by embedding in a larger word size, Word8.word probably being
the right choice.