futhark-0.19.5: An optimising compiler for a functional, array-oriented language.
Safe HaskellTrustworthy
LanguageHaskell2010

Futhark.Binder

Description

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

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

Instances details
MonadWriter w m => MonadWriter w (BinderT lore m) Source # 
Instance details

Defined in Futhark.Binder

Methods

writer :: (a, w) -> BinderT lore m a #

tell :: w -> BinderT lore m () #

listen :: BinderT lore m a -> BinderT lore m (a, w) #

pass :: BinderT lore m (a, w -> w) -> BinderT lore m a #

MonadState s m => MonadState s (BinderT lore m) Source # 
Instance details

Defined in Futhark.Binder

Methods

get :: BinderT lore m s #

put :: s -> BinderT lore m () #

state :: (s -> (a, s)) -> BinderT lore m a #

MonadReader r m => MonadReader r (BinderT lore m) Source # 
Instance details

Defined in Futhark.Binder

Methods

ask :: BinderT lore m r #

local :: (r -> r) -> BinderT lore m a -> BinderT lore m a #

reader :: (r -> a) -> BinderT lore m a #

MonadError e m => MonadError e (BinderT lore m) Source # 
Instance details

Defined in Futhark.Binder

Methods

throwError :: e -> BinderT lore m a #

catchError :: BinderT lore m a -> (e -> BinderT lore m a) -> BinderT lore m a #

(ASTLore lore, Monad m) => LocalScope lore (BinderT lore m) Source # 
Instance details

Defined in Futhark.Binder

Methods

localScope :: Scope lore -> BinderT lore m a -> BinderT lore m a Source #

(ASTLore lore, Monad m) => HasScope lore (BinderT lore m) Source # 
Instance details

Defined in Futhark.Binder

Methods

lookupType :: VName -> BinderT lore m Type Source #

lookupInfo :: VName -> BinderT lore m (NameInfo lore) Source #

askScope :: BinderT lore m (Scope lore) Source #

asksScope :: (Scope lore -> a) -> BinderT lore m a Source #

MonadTrans (BinderT lore) Source # 
Instance details

Defined in Futhark.Binder

Methods

lift :: Monad m => m a -> BinderT lore m a #

Monad m => Monad (BinderT lore m) Source # 
Instance details

Defined in Futhark.Binder

Methods

(>>=) :: BinderT lore m a -> (a -> BinderT lore m b) -> BinderT lore m b #

(>>) :: BinderT lore m a -> BinderT lore m b -> BinderT lore m b #

return :: a -> BinderT lore m a #

Functor m => Functor (BinderT lore m) Source # 
Instance details

Defined in Futhark.Binder

Methods

fmap :: (a -> b) -> BinderT lore m a -> BinderT lore m b #

(<$) :: a -> BinderT lore m b -> BinderT lore m a #

Monad m => Applicative (BinderT lore m) Source # 
Instance details

Defined in Futhark.Binder

Methods

pure :: a -> BinderT lore m a #

(<*>) :: BinderT lore m (a -> b) -> BinderT lore m a -> BinderT lore m b #

liftA2 :: (a -> b -> c) -> BinderT lore m a -> BinderT lore m b -> BinderT lore m c #

(*>) :: BinderT lore m a -> BinderT lore m b -> BinderT lore m b #

(<*) :: BinderT lore m a -> BinderT lore m b -> BinderT lore m a #

MonadFreshNames m => MonadFreshNames (BinderT lore m) Source # 
Instance details

Defined in Futhark.Binder

(ASTLore lore, MonadFreshNames m, BinderOps lore) => MonadBinder (BinderT lore m) Source # 
Instance details

Defined in Futhark.Binder

Associated Types

type Lore (BinderT lore m) Source #

Methods

mkExpDecM :: Pattern (Lore (BinderT lore m)) -> Exp (Lore (BinderT lore m)) -> BinderT lore m (ExpDec (Lore (BinderT lore m))) Source #

mkBodyM :: Stms (Lore (BinderT lore m)) -> Result -> BinderT lore m (Body (Lore (BinderT lore m))) Source #

mkLetNamesM :: [VName] -> Exp (Lore (BinderT lore m)) -> BinderT lore m (Stm (Lore (BinderT lore m))) Source #

addStm :: Stm (Lore (BinderT lore m)) -> BinderT lore m () Source #

addStms :: Stms (Lore (BinderT lore m)) -> BinderT lore m () Source #

collectStms :: BinderT lore m a -> BinderT lore m (a, Stms (Lore (BinderT lore m))) Source #

certifying :: Certificates -> BinderT lore m a -> BinderT lore m a Source #

type Lore (BinderT lore m) Source # 
Instance details

Defined in Futhark.Binder

type Lore (BinderT lore m) = lore

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.

Minimal complete definition

Nothing

Methods

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 #

default mkBodyB :: (MonadBinder m, Bindable 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

Instances details
BinderOps Seq Source # 
Instance details

Defined in Futhark.IR.Seq

Methods

mkExpDecB :: (MonadBinder m, Lore m ~ Seq) => Pattern Seq -> Exp Seq -> m (ExpDec Seq) Source #

mkBodyB :: (MonadBinder m, Lore m ~ Seq) => Stms Seq -> Result -> m (Body Seq) Source #

mkLetNamesB :: (MonadBinder m, Lore m ~ Seq) => [VName] -> Exp Seq -> m (Stm Seq) Source #

BinderOps SOACS Source # 
Instance details

Defined in Futhark.IR.SOACS

BinderOps MCMem Source # 
Instance details

Defined in Futhark.IR.MCMem

BinderOps MC Source # 
Instance details

Defined in Futhark.IR.MC

Methods

mkExpDecB :: (MonadBinder m, Lore m ~ MC) => Pattern MC -> Exp MC -> m (ExpDec MC) Source #

mkBodyB :: (MonadBinder m, Lore m ~ MC) => Stms MC -> Result -> m (Body MC) Source #

mkLetNamesB :: (MonadBinder m, Lore m ~ MC) => [VName] -> Exp MC -> m (Stm MC) Source #

BinderOps SeqMem Source # 
Instance details

Defined in Futhark.IR.SeqMem

BinderOps Kernels Source # 
Instance details

Defined in Futhark.IR.Kernels

BinderOps KernelsMem Source # 
Instance details

Defined in Futhark.IR.KernelsMem

(ASTLore (Aliases lore), Bindable (Aliases lore)) => BinderOps (Aliases lore) Source # 
Instance details

Defined in Futhark.IR.Aliases

Methods

mkExpDecB :: (MonadBinder m, Lore m ~ Aliases lore) => Pattern (Aliases lore) -> Exp (Aliases lore) -> m (ExpDec (Aliases lore)) Source #

mkBodyB :: (MonadBinder m, Lore m ~ Aliases lore) => Stms (Aliases lore) -> Result -> m (Body (Aliases lore)) Source #

mkLetNamesB :: (MonadBinder m, Lore m ~ Aliases lore) => [VName] -> Exp (Aliases lore) -> m (Stm (Aliases lore)) Source #

BinderOps (Wise Seq) Source # 
Instance details

Defined in Futhark.IR.Seq

Methods

mkExpDecB :: (MonadBinder m, Lore m ~ Wise Seq) => Pattern (Wise Seq) -> Exp (Wise Seq) -> m (ExpDec (Wise Seq)) Source #

mkBodyB :: (MonadBinder m, Lore m ~ Wise Seq) => Stms (Wise Seq) -> Result -> m (Body (Wise Seq)) Source #

mkLetNamesB :: (MonadBinder m, Lore m ~ Wise Seq) => [VName] -> Exp (Wise Seq) -> m (Stm (Wise Seq)) Source #

BinderOps (Wise SOACS) Source # 
Instance details

Defined in Futhark.IR.SOACS.Simplify

BinderOps (Wise MCMem) Source # 
Instance details

Defined in Futhark.IR.MCMem

BinderOps (Wise MC) Source # 
Instance details

Defined in Futhark.IR.MC

Methods

mkExpDecB :: (MonadBinder m, Lore m ~ Wise MC) => Pattern (Wise MC) -> Exp (Wise MC) -> m (ExpDec (Wise MC)) Source #

mkBodyB :: (MonadBinder m, Lore m ~ Wise MC) => Stms (Wise MC) -> Result -> m (Body (Wise MC)) Source #

mkLetNamesB :: (MonadBinder m, Lore m ~ Wise MC) => [VName] -> Exp (Wise MC) -> m (Stm (Wise MC)) Source #

BinderOps (Wise SeqMem) Source # 
Instance details

Defined in Futhark.IR.SeqMem

BinderOps (Wise Kernels) Source # 
Instance details

Defined in Futhark.IR.Kernels.Simplify

BinderOps (Wise KernelsMem) Source # 
Instance details

Defined in Futhark.IR.KernelsMem

type Binder lore = BinderT lore (State VNameSource) Source #

The most commonly used binder monad.

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 #

Run a binder that produces a Body, and prefix that Body by the statements produced during execution of the action.

The MonadBinder typeclass