{-# LANGUAGE TypeFamilies #-}
module Lib
(
) where
import Data.Char (ord, chr)
--
type family Rep a
type instance Rep Int = Char
type instance Rep Char = Int
class Convertible1 a where
convert1 :: a -> Rep a
instance Convertible1 Int where
convert1 = chr
instance Convertible1 Char where
convert1 = ord
-- (2) Associated form
class Convertible2 a where
type Rep2 a
convert2 :: a -> Rep2 a
instance Convertible2 Int where
type Rep2 Int = Char
convert2 = chr
instance Convertible2 Char where
type Rep2 Char = Int
convert2 = ord
--
newtype Age = MkAge { unAge :: Int }
type family Inspect x
type instance Inspect Age = Int
type instance Inspect Int = Bool
class Boom a where
boom :: a -> Inspect a
instance Boom Int where
boom = (== 0)
instance Boom Age where
boom = unAge
main = do
print $ convert1 'c'
print $ convert1 (42::Int)
print $ boom (MkAge 42)
print $ boom (42::Int)