futhark-0.19.7: 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 rep 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 rep m) Source # 
Instance details

Defined in Futhark.Binder

Methods

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

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

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

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

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

Defined in Futhark.Binder

Methods

get :: BinderT rep m s #

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

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

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

Defined in Futhark.Binder

Methods

ask :: BinderT rep m r #

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

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

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

Defined in Futhark.Binder

Methods

throwError :: e -> BinderT rep m a #

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

(ASTRep rep, Monad m) => LocalScope rep (BinderT rep m) Source # 
Instance details

Defined in Futhark.Binder

Methods

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

(ASTRep rep, Monad m) => HasScope rep (BinderT rep m) Source # 
Instance details

Defined in Futhark.Binder

Methods

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

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

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

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

MonadTrans (BinderT rep) Source # 
Instance details

Defined in Futhark.Binder

Methods

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

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

Defined in Futhark.Binder

Methods

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

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

return :: a -> BinderT rep m a #

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

Defined in Futhark.Binder

Methods

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

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

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

Defined in Futhark.Binder

Methods

pure :: a -> BinderT rep m a #

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

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

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

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

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

Defined in Futhark.Binder

(ASTRep rep, MonadFreshNames m, BinderOps rep) => MonadBinder (BinderT rep m) Source # 
Instance details

Defined in Futhark.Binder

Associated Types

type Rep (BinderT rep m) Source #

Methods

mkExpDecM :: Pattern (Rep (BinderT rep m)) -> Exp (Rep (BinderT rep m)) -> BinderT rep m (ExpDec (Rep (BinderT rep m))) Source #

mkBodyM :: Stms (Rep (BinderT rep m)) -> Result -> BinderT rep m (Body (Rep (BinderT rep m))) Source #

mkLetNamesM :: [VName] -> Exp (Rep (BinderT rep m)) -> BinderT rep m (Stm (Rep (BinderT rep m))) Source #

addStm :: Stm (Rep (BinderT rep m)) -> BinderT rep m () Source #

addStms :: Stms (Rep (BinderT rep m)) -> BinderT rep m () Source #

collectStms :: BinderT rep m a -> BinderT rep m (a, Stms (Rep (BinderT rep m))) Source #

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

type Rep (BinderT rep m) Source # 
Instance details

Defined in Futhark.Binder

type Rep (BinderT rep m) = rep

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.

Minimal complete definition

Nothing

Methods

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 #

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

Instances details
BinderOps Seq Source # 
Instance details

Defined in Futhark.IR.Seq

Methods

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

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

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

BinderOps SOACS Source # 
Instance details

Defined in Futhark.IR.SOACS

BinderOps SeqMem Source # 
Instance details

Defined in Futhark.IR.SeqMem

BinderOps MCMem Source # 
Instance details

Defined in Futhark.IR.MCMem

BinderOps MC Source # 
Instance details

Defined in Futhark.IR.MC

Methods

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

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

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

BinderOps GPU Source # 
Instance details

Defined in Futhark.IR.GPU

Methods

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

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

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

BinderOps GPUMem Source # 
Instance details

Defined in Futhark.IR.GPUMem

(ASTRep (Aliases rep), Bindable (Aliases rep)) => BinderOps (Aliases rep) Source # 
Instance details

Defined in Futhark.IR.Aliases

Methods

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

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

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

BinderOps (Wise Seq) Source # 
Instance details

Defined in Futhark.IR.Seq

Methods

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

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

mkLetNamesB :: (MonadBinder m, Rep 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 SeqMem) Source # 
Instance details

Defined in Futhark.IR.SeqMem

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, Rep m ~ Wise MC) => Pattern (Wise MC) -> Exp (Wise MC) -> m (ExpDec (Wise MC)) Source #

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

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

BinderOps (Wise GPU) Source # 
Instance details

Defined in Futhark.IR.GPU.Simplify

Methods

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

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

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

BinderOps (Wise GPUMem) Source # 
Instance details

Defined in Futhark.IR.GPUMem

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

The most commonly used binder monad.

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 #

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

The MonadBinder typeclass