What is a common idiom for converting between integral types?

I want to convert between different integral types; e.g. Word32 and Word8.

What is the idiomatic way to do this in Haskell?

Word8 -> Converting Word32 can always be successful. Converting Word32 -> Word8 can lead to overflow, and I will deal with this (either by checking explicitly, or by getting directions from any conversion idiom).

+6
integer haskell
source share
2 answers

fromIntegral converts from an integral type to any number type, including other integral types

+11
source share
+3
source share

All Articles