Herman Schoenfeld
Herman Schoenfeld

Reputation: 8724

How do I use Bits type in Haskell?

I am using WinHugs98 and I would like to do simple XOR of Int 10 with Int 11.

How do I do it?

Current Attempt:

Hugs> :l Data.Bits
Data.Bits> (Bits 10) `xor` (Bits 11)
ERROR - Undefined data constructor "Bits"

How do I convert the integer 10 and 11 to a "Bits" type so it can be used? Then I want to convert back to print on screen.

Edit for Louise Wasserman:

enter image description here

Upvotes: 1

Views: 191

Answers (1)

Louis Wasserman
Louis Wasserman

Reputation: 198063

There is no conversion to be done. Int is an instance of the Bits class, meaning the methods from Bits are defined for Int. Just use xor directly:

10 `xor` 11

Upvotes: 3

Related Questions