I want to convert Float to a list of bytes [Word8] (and vice versa). I see there is a Storable class which could maybe be used for this, but I’d like to avoid using IO monad as this has nothing to do with IO.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What is it that you want? If you want to convert between the Float and its actual bit representation, you can use data-binary-ieee754 (uses
Foreign.StorableandunsafePerformIOunder the hood) or cereal-ieee754. The latter doesn’t useStorableorIO, it writes the value to anSTUArray, casts the array and reads a value of the other type. Both packages give you a conversionFloat <-> Word32(orDouble <-> Word64), converting theWordNto[Word8]is easy.