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 lore m a
- runBinderT :: MonadFreshNames m => BinderT lore m a -> Scope lore -> m (a, Stms lore)
- runBinderT_ :: MonadFreshNames m => BinderT lore m () -> Scope lore -> m (Stms lore)
- runBinderT' :: (MonadFreshNames m, HasScope somelore m, SameScope somelore lore) => BinderT lore m a -> m (a, Stms lore)
- runBinderT'_ :: (MonadFreshNames m, HasScope somelore m, SameScope somelore lore) => BinderT lore m a -> m (Stms lore)
- class ASTLore lore => BinderOps lore where
- mkExpDecB :: (MonadBinder m, Lore m ~ lore) => Pattern lore -> Exp lore -> m (ExpDec lore)
- mkBodyB :: (MonadBinder m, Lore m ~ lore) => Stms lore -> Result -> m (Body lore)
- mkLetNamesB :: (MonadBinder m, Lore m ~ lore) => [VName] -> Exp lore -> m (Stm lore)
- type Binder lore = BinderT lore (State VNameSource)
- runBinder :: (MonadFreshNames m, HasScope somelore m, SameScope somelore lore) => Binder lore a -> m (a, Stms lore)
- runBinder_ :: (MonadFreshNames m, HasScope somelore m, SameScope somelore lore) => Binder lore a -> m (Stms lore)
- runBodyBinder :: (Bindable lore, MonadFreshNames m, HasScope somelore m, SameScope somelore lore) => Binder lore (Body lore) -> m (Body lore)
- module Futhark.Binder.Class
A concrete MonadBinder
monad.
data BinderT lore m a Source #
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 lore m a -> Scope lore -> m (a, Stms lore) Source #
Run a binder action given an initial scope, returning a value and
the statements added (addStm
) during the action.
runBinderT_ :: MonadFreshNames m => BinderT lore m () -> Scope lore -> m (Stms lore) Source #
Like runBinderT
, but return only the statements.
runBinderT' :: (MonadFreshNames m, HasScope somelore m, SameScope somelore lore) => BinderT lore m a -> m (a, Stms lore) Source #
Like runBinderT
, but get the initial scope from the current
monad.
runBinderT'_ :: (MonadFreshNames m, HasScope somelore m, SameScope somelore lore) => BinderT lore m a -> m (Stms lore) Source #
Like runBinderT_
, but get the initial scope from the current
monad.
class ASTLore lore => BinderOps lore where Source #
A BinderT
(and by extension, a Binder
) is only an instance of
MonadBinder
for lores that implement this type class, which
contains methods for constructing statements.
Nothing
mkExpDecB :: (MonadBinder m, Lore m ~ lore) => Pattern lore -> Exp lore -> m (ExpDec lore) Source #
default mkExpDecB :: (MonadBinder m, Bindable lore) => Pattern lore -> Exp lore -> m (ExpDec lore) Source #
mkBodyB :: (MonadBinder m, Lore m ~ lore) => Stms lore -> Result -> m (Body lore) Source #
mkLetNamesB :: (MonadBinder m, Lore m ~ lore) => [VName] -> Exp lore -> m (Stm lore) Source #
default mkLetNamesB :: (MonadBinder m, Lore m ~ lore, Bindable lore) => [VName] -> Exp lore -> m (Stm lore) Source #
Instances
runBinder :: (MonadFreshNames m, HasScope somelore m, SameScope somelore lore) => Binder lore a -> m (a, Stms lore) 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 somelore m, SameScope somelore lore) => Binder lore a -> m (Stms lore) Source #
Like runBinder
, but throw away the result and just return the
added statements.
runBodyBinder :: (Bindable lore, MonadFreshNames m, HasScope somelore m, SameScope somelore lore) => Binder lore (Body lore) -> m (Body lore) Source #
The MonadBinder
typeclass
module Futhark.Binder.Class