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
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
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
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
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
> > 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,
> 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
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
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
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
> 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
__
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
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
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
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
>
>
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
16 matches
Mail list logo