Haskell bitwise operators in Data.Bits

bit-manipulation, haskell

Solution

In the interactive session, Haskell can't infer the types of 1 and 16. The solution then, is to give a hint:

> :m +Data.Bits
> let a = 1 :: Int
> let b = 16 :: Int
> a `shiftL` b
65535
>

Problem

I am new to Haskell and am trying to use bitwise operations from Data.Bits. Every time I try I get an error message ``` Prelude Data.Bits> 1 `shiftL` 16 <interactive>:1:0: Ambiguous type variable `t' in the constraint: `Bits t' arising from a use of `shiftL' at <interactive>:1:0-12 Probable fix: add a type signature that fixes these type variable(s) ``` This happens for a number of operations, I also tried .|. and .&. I must be missing something very simple, please let me know if you can spot the problem

Original source