开发者

What is a common idiom for converting between Integral types?

开发者 https://www.devze.com 2022-12-20 05:02 出处:网络
I want to convert between various integral types; for example Word32 and Word8. What is the idiomatic way to do this in Haskell?

I want to convert between various integral types; for example Word32 and Word8.

What is the idiomatic way to do this in Haskell?

Word8 -> Word32 conversion ca开发者_开发百科n always succeed. Word32 -> Word8 conversion might result in an overflow and I'll deal with that (either by testing explicitly or getting an indication from whatever the conversion idiom is).


fromIntegral will convert from an integral type to any numeric type, including other integral types


See Converting Numbers in the Haskell wiki

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号