Safe Haskell | Trustworthy |
---|---|
Language | Haskell2010 |
This module defines a convenience monad/typeclass for creating
normalised programs. The fundamental building block is BinderT
and its execution functions, but it is usually easier to use
Binder
.
See Futhark.Construct for a high-level description.
Synopsis
- data BinderT rep m a
- runBinderT :: MonadFreshNames m => BinderT rep m a -> Scope rep -> m (a, Stms rep)
- runBinderT_ :: MonadFreshNames m => BinderT rep m () -> Scope rep -> m (Stms rep)
- runBinderT' :: (MonadFreshNames m, HasScope somerep m, SameScope somerep rep) => BinderT rep m a -> m (a, Stms rep)
- runBinderT'_ :: (MonadFreshNames m, HasScope somerep m, SameScope somerep rep) => BinderT rep m a -> m (Stms rep)
- class ASTRep rep => BinderOps rep where
- mkExpDecB :: (MonadBinder m, Rep m ~ rep) => Pattern rep -> Exp rep -> m (ExpDec rep)
- mkBodyB :: (MonadBinder m, Rep m ~ rep) => Stms rep -> Result -> m (Body rep)
- mkLetNamesB :: (MonadBinder m, Rep m ~ rep) => [VName] -> Exp rep -> m (Stm rep)
- type Binder rep = BinderT rep (State VNameSource)
- runBinder :: (MonadFreshNames m, HasScope somerep m, SameScope somerep rep) => Binder rep a -> m (a, Stms rep)
- runBinder_ :: (MonadFreshNames m, HasScope somerep m, SameScope somerep rep) => Binder rep a -> m (Stms rep)
- runBodyBinder :: (Bindable rep, MonadFreshNames m, HasScope somerep m, SameScope somerep rep) => Binder rep (Body rep) -> m (Body rep)
- module Futhark.Binder.Class
A concrete MonadBinder
monad.
A monad transformer that tracks statements and provides a
MonadBinder
instance, assuming that the underlying monad provides
a name source. In almost all cases, this is what you will use for
constructing statements (possibly as part of a larger monad stack).
If you find yourself needing to implement MonadBinder
from
scratch, then it is likely that you are making a mistake.
Instances
runBinderT :: MonadFreshNames m => BinderT rep m a -> Scope rep -> m (a, Stms rep) Source #
Run a binder action given an initial scope, returning a value and
the statements added (addStm
) during the action.
runBinderT_ :: MonadFreshNames m => BinderT rep m () -> Scope rep -> m (Stms rep) Source #
Like runBinderT
, but return only the statements.
runBinderT' :: (MonadFreshNames m, HasScope somerep m, SameScope somerep rep) => BinderT rep m a -> m (a, Stms rep) Source #
Like runBinderT
, but get the initial scope from the current
monad.
runBinderT'_ :: (MonadFreshNames m, HasScope somerep m, SameScope somerep rep) => BinderT rep m a -> m (Stms rep) Source #
Like runBinderT_
, but get the initial scope from the current
monad.
class ASTRep rep => BinderOps rep where Source #
A BinderT
(and by extension, a Binder
) is only an instance of
MonadBinder
for representations that implement this type class,
which contains methods for constructing statements.
Nothing
mkExpDecB :: (MonadBinder m, Rep m ~ rep) => Pattern rep -> Exp rep -> m (ExpDec rep) Source #
default mkExpDecB :: (MonadBinder m, Bindable rep) => Pattern rep -> Exp rep -> m (ExpDec rep) Source #
mkBodyB :: (MonadBinder m, Rep m ~ rep) => Stms rep -> Result -> m (Body rep) Source #
mkLetNamesB :: (MonadBinder m, Rep m ~ rep) => [VName] -> Exp rep -> m (Stm rep) Source #
default mkLetNamesB :: (MonadBinder m, Rep m ~ rep, Bindable rep) => [VName] -> Exp rep -> m (Stm rep) Source #
Instances
runBinder :: (MonadFreshNames m, HasScope somerep m, SameScope somerep rep) => Binder rep a -> m (a, Stms rep) Source #
Run a binder action, returning a value and the statements added
(addStm
) during the action. Assumes that the current monad
provides initial scope and name source.
runBinder_ :: (MonadFreshNames m, HasScope somerep m, SameScope somerep rep) => Binder rep a -> m (Stms rep) Source #
Like runBinder
, but throw away the result and just return the
added statements.
runBodyBinder :: (Bindable rep, MonadFreshNames m, HasScope somerep m, SameScope somerep rep) => Binder rep (Body rep) -> m (Body rep) Source #
The MonadBinder
typeclass
module Futhark.Binder.Class