[Haskell-cafe] what is wrong w my IORef Word32 ?

Joerg Fritsch fritsch at joerg.cc
Thu Jul 18 19:22:46 CEST 2013


Can I easily fix the modifyIORef statement by swapping "something" ?
--Joerg

On Jul 18, 2013, at 7:19 PM, "Edward Z. Yang" <ezyang at MIT.EDU> wrote:

> shiftL has the wrong type:  Bits a => a -> Int -> a
> so it is expecting the value in the IORef to be an Int.
> 
> Edward
> 
> Excerpts from Joerg Fritsch's message of Thu Jul 18 10:08:22 -0700 2013:
>> All, what is wrong w the below code?
>> 
>> I get an type error related to the operation shiftL
>> 
>> import Data.Bits
>> import Data.Word
>> import Data.IORef
>> 
>> data Word32s = Word32s { x :: IORef Word32 }
>> 
>> bitfield :: Word32
>> bitfield = 0
>> 
>> mkbitfield :: Word32 -> IO Word32s
>> mkbitfield i = do the_bf <- newIORef i
>>                  return (Word32s the_bf)
>> 
>> sLbitfield :: Integer -> Word32s -> IO ()
>> sLbitfield i (Word32s bf) = do modifyIORef bf (shiftL i)
>> 
>> main::IO()
>> main = do
>>     oper_bf <- mkbitfield bitfield 
>>     sLbitfield 2 oper_bf
>> 
>> 
>> 
>> bf_003.hs:15:48:
>>    Couldn't match type `Int' with `Word32'
>>    Expected type: Word32 -> Word32
>>      Actual type: Int -> Word32
>>    In the return type of a call of `shiftL'
>>    In the second argument of `modifyIORef', namely `(shiftL i)'
>>    In a stmt of a 'do' block: modifyIORef bf (shiftL i)
>> 
>> bf_003.hs:15:55:
>>    Couldn't match expected type `Word32' with actual type `Integer'
>>    In the first argument of `shiftL', namely `i'
>>    In the second argument of `modifyIORef', namely `(shiftL i)'
>>    In a stmt of a 'do' block: modifyIORef bf (shiftL i)
>> 
>> 
>> 
>> Thanks,
>> --Joerg
>> 





More information about the Haskell-Cafe mailing list