word bug (?)
Laudien, Joachim
Joachim.Laudien@fujitsu-siemens.com
Thu, 22 Aug 2002 16:40:21 +0200
Hi,
I found a "Pentomino Puzzle Solver in Haskell". Trying it, I got the error message
ERROR "D:\Games\Pentominos\PolyominoHaskell\FillBoard.lhs":208 - Instances of (Num Word64, Bits Word64) required for definition of ominoBits
So I looked into Word.hs and Bits.hs. While making Word64 an instance of Num was relatively straightforward by converting to Integer and back, I did not immediately understand the semantics of the bit operations. I started to experiment:
Word> (bit 7 :: Word8) `shift` 2
0
...
Now I'm totally confused: on the machine in my office, where I'm writing this mail, using Hugs December 2001 with Windows XP, I get the above, correct result. But at home, with the same Hugs and Windows NT 4, I get 512. Ah, I see, it's the show function...
Word> :s -u
Word> (bit 7 :: Word8) `shift` 2
512
But should it be left to the show to put the result into its range?
newtype Word8 = W8 Word32
word8ToWord32 (W8 x) = x .&. 0xff
word32ToWord8 = W8
Shouldn't it be the other way round
word8ToWord32 (W8 x) = x
word32ToWord8 = W8 (x .&. 0xff)
?
Kind regards,
Joachim Wolf Laudien