Safe Haskell | None |
---|---|
Language | Haskell98 |
This module provides the public interface to the template lifting library. It provides functions that input a Haskell declaration or expression (in the form of a Haskell abstract syntax tree), and lift this to another declaration or expression, with all functions lifted into a specified monad.
This can be combined with Template Haskell to convert source code to Haskell abstract syntax trees and vice versa.
Synopsis
- decToMonad :: String -> Q [Dec] -> Q [Dec]
- expToMonad :: String -> Q Exp -> Q Exp
- template_symb_colon_ :: Monad m => m (a -> m ([a] -> m [a]))
- template_symb_obracket_symb_cbracket_ :: Monad m => m [a]
- template_init :: Monad m => m ([a] -> m [a])
- template_last :: Monad m => m ([a] -> m a)
- template_symb_plus_symb_plus_ :: Monad m => m ([a] -> m ([a] -> m [a]))
- template_zip3 :: Monad m => m ([a] -> m ([b] -> m ([c] -> m [(a, b, c)])))
- template_foldl :: Monad m => m ((a -> m (b -> m a)) -> m (a -> m ([b] -> m a)))
- template_reverse :: Monad m => m ([a] -> m [a])
- template_zipWith :: Monad m => m ((a -> m (b -> m c)) -> m ([a] -> m ([b] -> m [c])))
- template_fold_right_zip :: Monad m => m (((a, b, c) -> m (a, d)) -> m ((a, [b], [c]) -> m (a, [d])))
- template_symb_dollar_ :: Monad m => m ((a -> m b) -> m (a -> m b))
- template_error :: Monad m => m (String -> m a)
- template_snd :: Monad m => m ((a, b) -> m b)
- data Q a
- data Dec
Example
We give an example to illustrate what is meant by "lifting" a term to a monad. Consider the expression
f = \g x -> g x x,
which has type
f :: (a -> a -> b) -> (a -> b).
We can lift this to the IO
monad by
- converting the expression to an abstract syntax tree, using the
special Template Haskell notation
;[| ... |]
- applying the
expToMonad
function; - converting the resulting abstract syntax tree back to a term,
using the special Template Haskell notation
.$( ... )
This allows us to write the following:
f' = $( expToMonad "IO" [| \g x -> g x x |] ),
which has type
f' :: IO ((a -> IO (a -> IO b)) -> IO (a -> IO b)),
and is in fact equivalent to
f'' = return $ \g -> return $ \x -> do h <- g x y <- h x return y
General lifting functions
decToMonad :: String -> Q [Dec] -> Q [Dec] Source #
Lift a list of declarations. The first argument is the name of the monad to lift into.
expToMonad :: String -> Q Exp -> Q Exp Source #
Lift an expression. The first argument is the name of the monad to lift into.
Liftings of specific constants
List operations
template_symb_colon_ :: Monad m => m (a -> m ([a] -> m [a])) Source #
Lifted version of '(:)' :: a -> [a] -> [a]
.
template_symb_obracket_symb_cbracket_ :: Monad m => m [a] Source #
Lifted version of '[]' :: [a]
.
template_init :: Monad m => m ([a] -> m [a]) Source #
Lifted version of
.init
:: [a] -> [a]
template_last :: Monad m => m ([a] -> m a) Source #
Lifted version of
.last
:: [a] -> [a]
template_symb_plus_symb_plus_ :: Monad m => m ([a] -> m ([a] -> m [a])) Source #
Lifted version of '(++)' :: [a] -> [a] -> [a]
.
template_zip3 :: Monad m => m ([a] -> m ([b] -> m ([c] -> m [(a, b, c)]))) Source #
Lifted version of zip3
.
template_foldl :: Monad m => m ((a -> m (b -> m a)) -> m (a -> m ([b] -> m a))) Source #
lifted version of foldl
template_reverse :: Monad m => m ([a] -> m [a]) Source #
lifted version of reverse
template_zipWith :: Monad m => m ((a -> m (b -> m c)) -> m ([a] -> m ([b] -> m [c]))) Source #
lifted version of zipWith
template_fold_right_zip :: Monad m => m (((a, b, c) -> m (a, d)) -> m ((a, [b], [c]) -> m (a, [d]))) Source #
Lifted version of fold_right_zip
Other operations
template_symb_dollar_ :: Monad m => m ((a -> m b) -> m (a -> m b)) Source #
Lifted version of the combinator $
.
template_error :: Monad m => m (String -> m a) Source #
template_snd :: Monad m => m ((a, b) -> m b) Source #
Lifted version of snd
:: (a,b) -> b
Re-exports from Language.Haskell.TH.
Instances
Monad Q | |
Functor Q | |
MonadFail Q | |
Defined in Language.Haskell.TH.Syntax | |
Applicative Q | |
MonadIO Q | |
Defined in Language.Haskell.TH.Syntax | |
Quasi Q | |
Defined in Language.Haskell.TH.Syntax qNewName :: String -> Q Name # qReport :: Bool -> String -> Q () # qRecover :: Q a -> Q a -> Q a # qLookupName :: Bool -> String -> Q (Maybe Name) # qReifyFixity :: Name -> Q (Maybe Fixity) # qReifyInstances :: Name -> [Type] -> Q [Dec] # qReifyRoles :: Name -> Q [Role] # qReifyAnnotations :: Data a => AnnLookup -> Q [a] # qReifyModule :: Module -> Q ModuleInfo # qReifyConStrictness :: Name -> Q [DecidedStrictness] # qAddDependentFile :: FilePath -> Q () # qAddTempFile :: String -> Q FilePath # qAddTopDecls :: [Dec] -> Q () # qAddForeignFilePath :: ForeignSrcLang -> String -> Q () # qAddModFinalizer :: Q () -> Q () # qAddCorePlugin :: String -> Q () # qGetQ :: Typeable a => Q (Maybe a) # qPutQ :: Typeable a => a -> Q () # qIsExtEnabled :: Extension -> Q Bool # qExtsEnabled :: Q [Extension] # |