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
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
>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With