Using newtypes or any data with unboxed Vectors

Henning Thielemann lemming at henning-thielemann.de
Sun Jul 12 16:40:46 UTC 2015



On Sun, 12 Jul 2015, Ken Bateman wrote:

> newtype SmallPos = Pos Int
>     deriving (Eq, Ord, Show)
> 
> smallPos :: Int -> SmallPos
> smallPos x | x > 0 && x < 100 = Pos x
>            | otherwise = error "bad SmallPos"
> 
> instance UnboxEquivalent SmallPos where
>     type UnboxEquiv SmallPos = Word8
>     toUnbox (Pos x) = fromIntegral x
>     fromUnbox x = (Pos (fromIntegral x))


I assume that something like this is already possible with the Unbox type 
class, but currently I cannot see how. :-(


More information about the Libraries mailing list