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

TypeMachine

Synopsis

Entrypoint

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

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

Main Type Functions

Is

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
      ...

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
      ...

Infixes

(<:>) :: LiftableTMFunction (a -> b) => (a -> b) -> TM a -> b Source #

Apply a `TM a` value to a TM computation that expects an a

Example:

 omit ["id"] <:> toType ''User

(<::>) :: LiftableTMFunction (Type -> a) => (Type -> a) -> Name -> a Source #

Allows passing a name to a TM function that takes a Type

 f <::> ''User == f <:> toType ''User

Internal types

data Type Source #

Data structure to easily manipulate Template Haskell's DataD

Instances

Instances details
Show Type Source # 
Instance details

Defined in TypeMachine.Type

Methods

showsPrec :: Int -> Type -> ShowS #

show :: Type -> String #

showList :: [Type] -> ShowS #

Eq Type Source # 
Instance details

Defined in TypeMachine.Type

Methods

(==) :: Type -> Type -> Bool #

(/=) :: Type -> Type -> Bool #

type TM a = WriterT [TypeMachineLog] Q a Source #

The TM (*TypeMachine*) monad can:

  • Emit warning messages (e.g. when omitting that does not exist)
  • Take advantage of the Q monad's features

Log types