How do you cast a foreign types like CInt to Int, or cast CInt to CLong, and moreover, how to deal with Enum. So far, for all of them I’ve been combining toEnum and fromEnum, but this seems hacky. Is there a proper way to do this?
fromIntegral should work here in both cases.
Enum types it might depend on the concrete type but using
toEnum seems fine.
Thank, that does work.
They’re ordinary newtypes from
import Foreign.C.Types qualified as FFI to :: (Int32, Int64, Int) -> (FFI.CInt, FFI.CLong, FFI.CBool) to (a, b, c) = (FFI.CInt a, FFI.CLong, toEnum c) fro :: (FFI.CInt, FFI.CLong, FFI.CBool) -> (Int32, Int64, Int) fro (FFI.CInt a, FFI.CLong b, c) = (a, b, c)