I would like create a polymorphic function that converts 8,16,32 bit words into 64 bit word. How can I do it?
UPDATE1
In the basis library all word structures have functions toLarge
and fromLarge
to convert to/from the LargeWord
, which is as far as I understand just a synonym for Word32.
UPDATE2
According to the spec, word size must be power of two, but in SML/NJ I have
Standard ML of New Jersey v110.84 [built: Mon Dec 03 10:23:14 2018]
- Word.wordSize;
val it = 31 : int
- Word32.wordSize;
val it = 32 : int
- Word.toLarge;
val it = fn : word -> Word32.word
> LargeWord.wordSize;
val it = 32 : int
while in PolyML
Poly/ML 5.7.1 Release
> Word.wordSize;
val it = 63: int
> Word64.wordSize;
val it = 64: int
> Word.toLarge;
val it = fn: word -> ?.word
> LargeWord.wordSize;
val it = 64: int
How is that? Why Word.wordSize
is not power of two? And why Word
representation differs in these SML implementations?
UPDATE3
Actually, I want to be able "promote" smaller words into the larger ones using (<<) operator, but cannot figure it out how to do it.
UPDATE4
It seems that Word
and LargeWord
depend on the architecture and represent a machine word. Because SML/NJ does not support 64-bit arch, it has different word size.