Can anyone explain this? Hugs doesn't complain. Prelude> :set --version The Glorious Glasgow Haskell Compilation System, version 5.04.1 test.hs:5: No instance for (Num Bool) arising from the instance declaration at test.hs:5 In the instance declaration for `Bits Bool' module Main(main) where import Bits instance Bits Bool where complement False = True complement True = False Dominic Steinitz
Dominic Steinitz wrote:
Can anyone explain this? Hugs doesn't complain.
Prelude> :set --version The Glorious Glasgow Haskell Compilation System, version 5.04.1
test.hs:5: No instance for (Num Bool) arising from the instance declaration at test.hs:5 In the instance declaration for `Bits Bool'
module Main(main) where
import Bits
instance Bits Bool where complement False = True complement True = False
GHC's definition of Bits requires that instances of Bits are also instances of Num. This constraint is required for the default implementations of bit and testBit: bit i = 1 `shift` i x `testBit` i = (x .&. bit i) /= 0 -- Glynn Clements <glynn.clements@virgin.net>
Is this a recent change? I've downloaded Ian Lynagh's DES module and it doesn't compile because of this. I assume it used to. I don't see the rationale for this. I can see Bool can be an instance of Bit but why does it need to be an instance of Num? Dominic Steinitz ----- Original Message ----- From: "Glynn Clements" <glynn.clements@virgin.net> To: "Dominic Steinitz" <dominic.steinitz@blueyonder.co.uk> Cc: <haskell@haskell.org> Sent: Sunday, April 06, 2003 2:35 PM Subject: Re: Bits Problem
Dominic Steinitz wrote:
Can anyone explain this? Hugs doesn't complain.
Prelude> :set --version The Glorious Glasgow Haskell Compilation System, version 5.04.1
test.hs:5: No instance for (Num Bool) arising from the instance declaration at test.hs:5 In the instance declaration for `Bits Bool'
module Main(main) where
import Bits
instance Bits Bool where complement False = True complement True = False
GHC's definition of Bits requires that instances of Bits are also instances of Num.
This constraint is required for the default implementations of bit and testBit:
bit i = 1 `shift` i x `testBit` i = (x .&. bit i) /= 0
-- Glynn Clements <glynn.clements@virgin.net>
I'm confused. Does it mean that objects basing on bits have to be of Num because of an default implementation that they don't use? A List of Bits should be instance of Bits, too. Instead of default imlementations that use Num functions, there could be an instance of all Integrals. (Integer is instance of Bits too, so there should not be any problem with rotations.) class Bits a where ... instance (Integral a) => Bits a where ... Am Sonntag, 6. April 2003 15:35 schrieb Glynn Clements:
Dominic Steinitz wrote:
Can anyone explain this? Hugs doesn't complain.
Prelude> :set --version The Glorious Glasgow Haskell Compilation System, version 5.04.1
test.hs:5: No instance for (Num Bool) arising from the instance declaration at test.hs:5 In the instance declaration for `Bits Bool'
module Main(main) where
import Bits
instance Bits Bool where complement False = True complement True = False
GHC's definition of Bits requires that instances of Bits are also instances of Num.
This constraint is required for the default implementations of bit and testBit:
bit i = 1 `shift` i x `testBit` i = (x .&. bit i) /= 0
participants (3)
-
Dominic Steinitz -
Glynn Clements -
Marc Ziegert