indigo-0.2.1: Convenient imperative eDSL over Lorentz.
Safe HaskellNone
LanguageHaskell2010

Indigo.Internal.State

Contents

Description

This module contains the core of Indigo language: the IndigoState monad, a datatype that represents its state. It also includes some convenient functions to work with the state in IndigoM, to provide rebindable syntax.

The IndigoState monad implements the functionality of a symbolic interpreter. During its execution Lorentz code is being generated.

Synopsis

Indigo State

newtype IndigoState inp out a Source #

IndigoState monad. It's basically Control.Monad.Indexed.State , however this package is not in the used lts and it doesn't compile.

It takes as input a MetaData (for the initial state) and returns a GenCode (for the resulting state and the generated Lorentz code).

IndigoState has to be used to write backend typed Lorentz code from the corresponding frontend constructions.

Constructors

IndigoState 

Fields

Instances

Instances details
Functor (IndigoState inp out) Source # 
Instance details

Defined in Indigo.Internal.State

Methods

fmap :: (a -> b) -> IndigoState inp out a -> IndigoState inp out b #

(<$) :: a -> IndigoState inp out b -> IndigoState inp out a #

usingIndigoState :: MetaData inp -> IndigoState inp out a -> GenCode inp out a Source #

(>>=) :: forall inp out out1 a b. IndigoState inp out a -> (a -> IndigoState out out1 b) -> IndigoState inp out1 b Source #

Bind for rebindable syntax.

It's basically like the bind for the State monad, but it also composes the generated code from m a and a -> m b.

(=<<) :: (a -> IndigoState out out1 b) -> IndigoState inp out a -> IndigoState inp out1 b Source #

(>>) :: IndigoState inp out a -> IndigoState out out1 b -> IndigoState inp out1 b Source #

Then for rebindable syntax.

(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 #

An infix synonym for fmap.

The name of this operator is an allusion to $. Note the similarities between their types:

 ($)  ::              (a -> b) ->   a ->   b
(<$>) :: Functor f => (a -> b) -> f a -> f b

Whereas $ is function application, <$> is function application lifted over a Functor.

Examples

Expand

Convert from a Maybe Int to a Maybe String using show:

>>> show <$> Nothing
Nothing
>>> show <$> Just 3
Just "3"

Convert from an Either Int Int to an Either Int String using show:

>>> show <$> Left 17
Left 17
>>> show <$> Right 17
Right "17"

Double each element of a list:

>>> (*2) <$> [1,2,3]
[2,4,6]

Apply even to the second element of a pair:

>>> even <$> (2,2)
(2,True)

return :: a -> IndigoState inp inp a Source #

Return for rebindable syntax.

iget :: IndigoState inp inp (MetaData inp) Source #

Get current MetaData.

iput :: GenCode inp out a -> IndigoState inp out a Source #

Put new GenCode.

data RefId Source #

Reference id to a stack cell

Instances

Instances details
Eq RefId Source # 
Instance details

Defined in Indigo.Internal.State

Methods

(==) :: RefId -> RefId -> Bool #

(/=) :: RefId -> RefId -> Bool #

Num RefId Source # 
Instance details

Defined in Indigo.Internal.State

Ord RefId Source # 
Instance details

Defined in Indigo.Internal.State

Methods

compare :: RefId -> RefId -> Ordering #

(<) :: RefId -> RefId -> Bool #

(<=) :: RefId -> RefId -> Bool #

(>) :: RefId -> RefId -> Bool #

(>=) :: RefId -> RefId -> Bool #

max :: RefId -> RefId -> RefId #

min :: RefId -> RefId -> RefId #

Real RefId Source # 
Instance details

Defined in Indigo.Internal.State

Methods

toRational :: RefId -> Rational #

Show RefId Source # 
Instance details

Defined in Indigo.Internal.State

Methods

showsPrec :: Int -> RefId -> ShowS #

show :: RefId -> String #

showList :: [RefId] -> ShowS #

Generic RefId Source # 
Instance details

Defined in Indigo.Internal.State

Associated Types

type Rep RefId :: Type -> Type #

Methods

from :: RefId -> Rep RefId x #

to :: Rep RefId x -> RefId #

type Rep RefId Source # 
Instance details

Defined in Indigo.Internal.State

type Rep RefId = D1 ('MetaData "RefId" "Indigo.Internal.State" "indigo-0.2.1-inplace" 'True) (C1 ('MetaCons "RefId" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Word)))

data StkEl a where Source #

Stack element of the symbolic interpreter.

It holds either a reference index that refers to this element or just NoRef, indicating that there are no references to this element.

Constructors

NoRef :: KnownValue a => StkEl a 
Ref :: KnownValue a => RefId -> StkEl a 

Instances

Instances details
TestEquality StkEl Source # 
Instance details

Defined in Indigo.Internal.State

Methods

testEquality :: forall (a :: k) (b :: k). StkEl a -> StkEl b -> Maybe (a :~: b) #

type StackVars (stk :: [Type]) = Rec StkEl stk Source #

Stack of the symbolic interpreter.

data GenCode inp out a Source #

Resulting state of IndigoM.

Constructors

GenCode 

Fields

Instances

Instances details
Functor (GenCode inp out) Source # 
Instance details

Defined in Indigo.Internal.State

Methods

fmap :: (a -> b) -> GenCode inp out a -> GenCode inp out b #

(<$) :: a -> GenCode inp out b -> GenCode inp out a #

data MetaData stk Source #

Initial state of IndigoState.

Constructors

MetaData 

Fields

Instances

Instances details
(KnownValue x, Default (MetaData xs)) => Default (MetaData (x ': xs)) Source # 
Instance details

Defined in Indigo.Internal.State

Methods

def :: MetaData (x ': xs) #

Default (MetaData ('[] :: [Type])) Source # 
Instance details

Defined in Indigo.Internal.State

Methods

def :: MetaData '[] #

cleanGenCode :: GenCode inp out a -> inp :-> inp Source #

Produces the generated Lorentz code that cleans after itself, leaving the same stack as the input one