I read in the structure from a binary file that contains signed 16-bit integers using the Get monad from Data.Binary . My current code is as follows:
data DetectorStats = DetectorStats Int16 Word8 Word8 Word8 Int16 Version Int16 deriving Show getDetectorStats :: Get DetectorStats getDetectorStats = do productNumber <- getWord16be bitPerCoordinate <- getWord8 energyCapability <- getWord8 timingCapability <- getWord8 clockFrequency <- getWord16be serialNumber <- getWord16be return (DetectorStats (unsafeCoerce productNumber ) bitPerCoordinate energyCapability timingCapability (unsafeCoerce clockFrequency) firmwareVersion (unsafeCoerce serialNumber))
I am not happy with using unsafeCoerce , but there seems to be no way to read Int16 directly, nor is there a way to convert Word16 to Int16 . Is there a better way to handle this?
binary haskell
user640078
source share