
12 Jul
2015
12 Jul
'15
12:40 p.m.
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. :-(