type-machine-0.1.0.1: Type-level functions for record types
Safe HaskellNone
LanguageHaskell2010

TypeMachine.TH

Synopsis

Documentation

type_ :: String -> TM Type -> Q [Dec] Source #

Entrypoint of TypeMachine. Create a new data type using a TM computation

deriveIs :: Name -> Name -> Q [Dec] Source #

Returns the declaration of the instance of Is for a given type

 > deriveIs ''Animal ''Dog

   instance IsAnimal Dog where
      ...

defineIs :: Name -> Q [Dec] Source #

Define the Is class for the given type and generate the To function

 > data User = User { id :: Int, name :: String }
 > defineIs ''User

 class IsUser a where
      getId :: a -> Int
      getName :: a -> String

      setId :: Int -> a -> a
      setName :: String -> a -> a

      toUser :: (IsUser a) => a -> User
      toUser a = User (getId a) (getName a)

 instance IsUser User where
      ...