Safe Haskell | None |
---|
- newtype ExpM t a = ExpM {}
- type ExpG t = ExpM t Exp
- type family ExpType a :: *
- runExpM :: ExpM t a -> (a, Set ModuleName)
- newName :: String -> ExpM t Name
- useValue :: String -> Name -> ExpG a
- useCon :: String -> Name -> ExpM t QName
- useVar :: Name -> ExpG t
- caseE :: ExpG x -> [(Pat, ExpG t)] -> ExpG t
- applyE :: ExpG (a -> b) -> ExpG a -> ExpG b
- applyE2 :: ExpG (a -> b -> c) -> ExpG a -> ExpG b -> ExpG c
- applyE3 :: ExpG (a -> b -> c -> d) -> ExpG a -> ExpG b -> ExpG c -> ExpG d
- applyE4 :: ExpG (a -> b -> c -> d -> e) -> ExpG a -> ExpG b -> ExpG c -> ExpG d -> ExpG e
- applyE5 :: ExpG (a -> b -> c -> d -> e -> f) -> ExpG a -> ExpG b -> ExpG c -> ExpG d -> ExpG e -> ExpG f
- applyE6 :: ExpG (a -> b -> c -> d -> e -> f -> g) -> ExpG a -> ExpG b -> ExpG c -> ExpG d -> ExpG e -> ExpG f -> ExpG g
- (<>$) :: ExpG (a -> b) -> ExpG a -> ExpG b
- class GenExp t where
- type GenExpType t :: *
- expr :: t -> ExpG (GenExpType t)
- newtype ModuleM a = ModuleM (Writer (Set ModuleName, [Decl]) a)
- type ModuleG = ModuleM (Maybe [ExportSpec])
- data FunRef t = FunRef Name
- data Name
- exportFun :: FunRef t -> ExportSpec
- addDecl :: Name -> ExpG t -> ModuleM (FunRef t)
- runModuleM :: ModuleG -> String -> Module
- generateModule :: ModuleG -> String -> String
Documentation
A ExpM is a monad used to track the imports that are needed for a given expression. Usually, you don't have to use this type directly, but use combinators to combine several ExpM into bigger expressions. The t type parameter tracks the type of the expression, so you don't accidently build expression that don't type check.
type ExpG t = ExpM t ExpSource
The ExpG type is a ExpM computation that returns an expression. Usually, this is the end result of a function generating a haskell expression
type family ExpType a :: *Source
This type family can be used to get the type associated with some expression.
runExpM :: ExpM t a -> (a, Set ModuleName)Source
Evaluate a ExpM action, returning the needed modules and the value.
newName :: String -> ExpM t NameSource
Generate a new unique variable name with the given prefix. Note that this new variable name is only unique relative to other variable names generated by this function.
useValue :: String -> Name -> ExpG aSource
Import a function from a module. This function is polymorphic in the type of the resulting expression, you should probably only use this function to define type-restricted specializations.
Example:
addInt :: ExpG (Int -> Int -> Int) -- Here we restricted the type to something sensible addInt = useValue "Prelude" $ Symbol "+"
useCon :: String -> Name -> ExpM t QNameSource
Import a value constructor from a module. Returns the qualified name of the constructor.
applyE :: ExpG (a -> b) -> ExpG a -> ExpG bSource
Apply a function in a haskell expression to a value.
applyE3 :: ExpG (a -> b -> c -> d) -> ExpG a -> ExpG b -> ExpG c -> ExpG dSource
Apply a function to 3 arguments
applyE4 :: ExpG (a -> b -> c -> d -> e) -> ExpG a -> ExpG b -> ExpG c -> ExpG d -> ExpG eSource
Apply a function to 4 arguments
applyE5 :: ExpG (a -> b -> c -> d -> e -> f) -> ExpG a -> ExpG b -> ExpG c -> ExpG d -> ExpG e -> ExpG fSource
Apply a function to 5 arguments
applyE6 :: ExpG (a -> b -> c -> d -> e -> f -> g) -> ExpG a -> ExpG b -> ExpG c -> ExpG d -> ExpG e -> ExpG f -> ExpG gSource
Apply a function to 6 arguments
Generate a expression from a haskell value.
type GenExpType t :: *Source
expr :: t -> ExpG (GenExpType t)Source
This function generates the haskell expression from the given haskell value.
A module keeps track of the needed imports, but also has a list of declarations in it.
ModuleM (Writer (Set ModuleName, [Decl]) a) |
type ModuleG = ModuleM (Maybe [ExportSpec])Source
This is the resulting type of a function generating a module. It is a ModuleM action returning the export list.
data Name
This type is used to represent variables, and also constructors.
exportFun :: FunRef t -> ExportSpecSource
Generate a ExportSpec for a given function item.
addDecl :: Name -> ExpG t -> ModuleM (FunRef t)Source
Add a declaration to the module. Return a reference to it that can be used to either apply the function to some values or export it.
runModuleM :: ModuleG -> String -> ModuleSource
Extract the Module from a module generator.
generateModule :: ModuleG -> String -> StringSource
Generate the source code for a module.