ddc-core-simpl-0.4.1.2: Disciplined Disciple Compiler code transformations.

Safe HaskellNone

DDC.Core.Transform.Thread

Description

Thread a state token through calls to given functions.

ASSUMPTIONS: * Program is a-normalized and fully named.

Synopsis

Documentation

class Thread c whereSource

Class of things that can have a state token threaded through them.

Methods

thread :: (Ord n, Show n, Pretty n) => Config a n -> KindEnv n -> TypeEnv n -> c (AnTEC a n) n -> c a nSource

Instances

data Config a n Source

Configuration for the Thread transform.

Constructors

Config 

Fields

configCheckConfig :: Config n

Config for the type checker. We need to reconstruct the type of the result of stateful functions when bundling them into the tuple that holds the state token.

configThreadMe :: n -> Type n -> Maybe (Type n)

Function to decide which top-level bindings are stateful and need the state token threaded through them. If the binding with the given name is stateful then the function should return the new type for the binding that accepts and returns the state token.

configTokenType :: Type n

Type of the state token to use.

configVoidType :: Type n

Type that represents a missing value. If a stateful function returns a void then our thread transform rewrites it to return the state token, instead of a tuple that contains the token as well as a void value.

configWrapResultType :: Type n -> Type n

Wrap a type with the world token. eg change Int to (World#, Int)

configWrapResultExp :: Exp (AnTEC a n) n -> Exp (AnTEC a n) n -> Exp a n

Wrap a result expression with the state token. The function is given the types of the world token and result, then the expressions for the same.

configThreadPat :: n -> Maybe (Bind n -> [Bind n] -> Pat n)

Make a pattern which binds the world argument from a threaded primop.

injectStateType :: Eq n => Config a n -> Type n -> Type nSource

Inject the state token into the type of an effectful function. Eg, change ([a b : Data]. a -> b -> Int) to ([a b : Data]. a -> b -> World -> (World, Int)