Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-06-26 Thread Edward Kmett
Agreed. I wound up having to add a horrible Num instance for Bool in 'monoids' in order to support a decent Boolean Ring type. http://comonad.com/haskell/monoids/dist/doc/html/monoids/Data-Ring-Boolean.html I would much rather be able to get rid of it! The only problem with eliminating the const

Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-06-24 Thread John Meacham
On Fri, May 08, 2009 at 04:36:41PM +0200, Stephan Friedrichs wrote: > When looking for an xor function, I found one in Data.Bits but couldn't > use it for Bool, because Bool is no instance of Bits and of Num (which > would be necessary, because it's "class (Num b) => Bits b"). My question > is: Why

Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-09 Thread Stephan Friedrichs
Neil Mitchell wrote: > > [...] > > Which is a shame, having Bits on Bool seems entirely logical, having > Num a superclass of Bits seems a little less clear. > There are two default implementations in Bits bit i = 1 `shiftL` i x `testBit` i = (x .&. bit i) /= 0 which rely on N

Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread Daniel Fischer
Am Freitag 08 Mai 2009 19:18:37 schrieb Brandon S. Allbery KF8NH: > On May 8, 2009, at 12:00 , Neil Brown wrote: > > If you change fromInteger in Num Bool to be fromInteger x = x /= 0, > > then we could all start writing nasty C-like if-expressions... > > I'd be strongly tempted to say > > > fromI

Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread Brandon S. Allbery KF8NH
On May 8, 2009, at 12:00 , Neil Brown wrote: If you change fromInteger in Num Bool to be fromInteger x = x /= 0, then we could all start writing nasty C-like if-expressions... I'd be strongly tempted to say > fromInteger = const False -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell

Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread John Dorsey
> > Does that also mean that you could write: > > > > if 3 - 4 then ... else ...  (= if (fromInteger 3 :: Bool) - (fromInteger 4 > > :: Bool) then ... else ...) > > No. 3 - 4 is an Integer, the proposal is to convert Bools to Ints, not > Ints to Bools. Rather, (3 - 4) is a "(Num t) => t", so yes,

Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread Neil Mitchell
> Does that also mean that you could write: > > if 3 - 4 then ... else ...  (= if (fromInteger 3 :: Bool) - (fromInteger 4 > :: Bool) then ... else ...) No. 3 - 4 is an Integer, the proposal is to convert Bools to Ints, not Ints to Bools. Of course, Lennart has been asking for precisely this funct

Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread Neil Brown
Neil Mitchell wrote: I didn't at first, then I remembered: 1 + True = fromInteger 1 + True And if we have Num for Bool, it type checks. Does that also mean that you could write: if 3 - 4 then ... else ... (= if (fromInteger 3 :: Bool) - (fromInteger 4 :: Bool) then ... else ...) or per

Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread Neil Mitchell
Nope, it's in the Haskell standard. It means we can type: 1 + (2 :: Int) and have it work Otherwise what type would 1 have? Integer? Float? It's just a way of giving constants the type :: Num a => a On Fri, May 8, 2009 at 4:53 PM, Andrew Wagner wrote: > Hmm, I never knew that. Is that a GHC thi

Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread Andrew Wagner
Hmm, I never knew that. Is that a GHC thing? Is it strictly necessary? Seems like it could be done in the Num instance for Integers, Ints, etc. On Fri, May 8, 2009 at 11:51 AM, Neil Mitchell wrote: > > Err, I'm not seeing the danger of this > > (+) :: forall a. (Num a) => a -> a -> a > > Doesn't

Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread Neil Mitchell
> Err, I'm not seeing the danger of this > (+) :: forall a. (Num a) => a -> a -> a > Doesn't this require the two parameters to be the same instance of Num? I didn't at first, then I remembered: 1 + True = fromInteger 1 + True And if we have Num for Bool, it type checks. Thanks Neil __

Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread Andrew Wagner
Err, I'm not seeing the danger of this (+) :: forall a. (Num a) => a -> a -> a Doesn't this require the two parameters to be the same instance of Num? On Fri, May 8, 2009 at 10:51 AM, Sittampalam, Ganesh < ganesh.sittampa...@credit-suisse.com> wrote: > Stephan Friedrichs wrote: > > > When lookin

RE: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread Sittampalam, Ganesh
Stephan Friedrichs wrote: > When looking for an xor function, I found one in Data.Bits but > couldn't use it for Bool, because Bool is no instance of Bits and of > Num (which would be necessary, because it's "class (Num b) => Bits > b"). My question is: Why not? > > [...] > quite trivial... Why

Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread Stephan Friedrichs
Deniz Dogan wrote: >> instance Num Bool where >>(+) False = id >>(+) True = not >> >>(*) True True = True >>(*) _ _= False >> > > Isn't "XOR" for booleans (/=)? Oh right. And (*) would be (&&): instance Num Bool where (+) = (/=) (*) = (&&) -- ... //Stephan

Re: [Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread Deniz Dogan
2009/5/8 Stephan Friedrichs : > Hi! > > When looking for an xor function, I found one in Data.Bits but couldn't > use it for Bool, because Bool is no instance of Bits and of Num (which > would be necessary, because it's "class (Num b) => Bits b"). My question > is: Why not? > > We could declare > >

[Haskell-cafe] Why is Bool no instance of Num and Bits?

2009-05-08 Thread Stephan Friedrichs
Hi! When looking for an xor function, I found one in Data.Bits but couldn't use it for Bool, because Bool is no instance of Bits and of Num (which would be necessary, because it's "class (Num b) => Bits b"). My question is: Why not? We could declare instance Num Bool where (+) False = id