On 20/08/12 23:03, Gael Mulat wrote:
Hi,
Trying to port my code from SML/NJ to Poly/ML, I?m stuck with the Word31 structure.
In SML/NJ, Word = Word31 and WORD signature defines operators <<, >> and ~>> like this:
val op << : word * Word31.word -> word
which is the same as
val op << : word * Word.word -> word
This means that Word31 is the right operand for this operator, even in word32 and in Word64 structures.
E.g. no problem with
Word64.<< (0w1, 0w8 : Word.word);
My code base is built on this signature (would be hard to change it everywhere; and would no more be OK for SML/NJ).
Does someone have a trick to port this to Poly/ML ?
Assuming you don't really need 31 bit words, my advice would be to use Word (which all platforms have) rather than Word31. Although Word.wordSize can vary across platforms, I find it highly unlikely that this will be an issue for representing the number of bits to shift. With SML/NJ it is 31 and with Poly/ML it is 63 (at least on x86_64 platforms). So hopefully you can fix this by replacing references to Word31.
Relying on Word31 is not advisable for portability as this is an optional structure in the Basis Library.
Also, if you must make use of Word31, don't assume that Word31 = Word. For example, if a Word<N>.word is used where a Word.word is specified in the Basis Library, convert with
(Word.fromLarge o Word<N>.toLarge)
On platforms where unnecessary, the conversion should be optimized away. I have to say, if find it surprising that compilers even allow Word.word to match the equivalent size Word<N>.word given the specification in the Basis Library http://www.standardml.org/Basis/word.html
structure Word :> WORD where type word = word structure Word<N> :> WORD (* OPTIONAL *)
which uses opaque signature matching and has no 'where type' clause for Word<N>.
Phil