Ticket #10634: TypeFunctionBijection.hs

File TypeFunctionBijection.hs, 447 bytes (added by Lemming, 4 years ago)
Line 
1{-# LANGUAGE TypeFamilies #-}
2module TypeFunctionBijection where
3
4import Data.Int (Int8, Int16, Int32)
5
6type family Up a
7type instance Up Int8  = Int16
8type instance Up Int16 = Int32
9
10class (Up (Down a) ~ a) => Convert a where
11   type Down a
12   down :: a -> Down a
13
14instance Convert Int16 where
15   type Down Int16 = Int8
16   down = fromIntegral
17
18instance Convert Int32 where
19   type Down Int32 = Int16
20   down = fromIntegral
21
22
23x :: Int8
24x = down 8