1) How do you convert from one type Int to type Num ?
Similar questions were asked before, and the answer was (like on the Haskell wiki) - use fromIntegral . fromIntegral returns a Num type, so I have to specify it in the desired format.
I need to take Word16 and convert it to Int64 , so I do the following
let valueLength = (fromIntegral(tagLength) :: Int64)
where tagLength is of type Word16
Is this approach right?
2) How do you handle type conversion safely?
Based on the Java background, where there is for integers, I consider Short , Int and Long I can use Short as Int , but not vice versa. In Haskell though, if I write
256 :: Word8
in ghci it returns 0.
source share