Safe Haskell | None |
---|---|
Language | Haskell98 |
Language.AbstractSyntax.TTTAS
Contents
Description
Library for Typed Transformations of Typed Abstract Syntax.
The library is documented in the paper: Typed Transformations of Typed Abstract Syntax
Bibtex entry: http://www.cs.uu.nl/wiki/bin/viewfile/Center/TTTAS?rev=1;filename=TTTAS.bib
For more documentation see the TTTAS webpage: http://www.cs.uu.nl/wiki/bin/view/Center/TTTAS.
For an example see examples/CSE1.hs
- module Language.AbstractSyntax.TTTAS.Common
- data Trafo m t s a b = Trafo (forall env1. m env1 -> TrafoE m t s env1 a b)
- data TrafoE m t s env1 a b = forall env2 . TrafoE (m env2) (a -> T env2 s -> Env t s env1 -> FinalEnv t s -> (b, T env1 s, Env t s env2, FinalEnv t s))
- newSRef :: Trafo Unit t s (t a s) (Ref a s)
- extEnv :: m (e, a) -> TrafoE m t s e (t a s) (Ref a s)
- castSRef :: m e -> Ref a e -> TrafoE m t s e x (Ref a s)
- updateSRef :: m e -> Ref a e -> (i -> t a s -> t a s) -> TrafoE m t s e i (Ref a s)
- getFinalEnv :: Trafo m t s () (FinalEnv t s)
- putFinalEnv :: Trafo m t s (FinalEnv t s) ()
- updateFinalEnv :: Trafo m t s (FinalEnv t s -> FinalEnv t s) ()
- runTrafo :: (forall s. Trafo m t s a (b s)) -> m () -> a -> Result m t b
- sequenceA :: [Trafo m t s a b] -> Trafo m t s a [b]
Typed References and Environments
Transformation Library
Trafo
The type Trafo
is the type of the transformation steps on a heterogeneous collection.
The argument m
stands for the type of the meta-data.
A |Trafo| takes the meta-data on the current environment |env1| as input and
yields meta-data for the (possibly extended) environment |env2|.
The type t
is the type of the terms stored in the environment.
The type variable s
represents the type of the final result, which we do expose.
Its role is similar to the s
in the type ST s a
.
The arguments a
and b
are the Arrow's input and output, respectively.
data TrafoE m t s env1 a b Source
The type TrafoE
is used to introduce an existential quantifier into
the definition of Trafo
.
It can be seen that a Trafo
is a function taking as arguments: the input (a
),
a Ref
-transformer (T env2 s
) from the environment constructed in this step
to the final environment, the environment (Env t s env1
) where the current
transformation starts and the "final environment" (FinalEnv t s
)
with the updates thus far applied.
The function returns: the output (b
),
a Ref
-transformer (T env1 s
) from the initial environment of this step to the final
environment, the environment (Env t s env2
) constructed in this step and the final environment
(FinalEnv t s
) possibly updated.
Create New References
updateSRef :: m e -> Ref a e -> (i -> t a s -> t a s) -> TrafoE m t s e i (Ref a s) Source
The function updateSRef
returns a TrafoE
that updates the value pointed
by the reference passed as parameter into the current environment.
State-like operations on the Final Environment
getFinalEnv :: Trafo m t s () (FinalEnv t s) Source
Return as output the final environment.
putFinalEnv :: Trafo m t s (FinalEnv t s) () Source
Change the final environment by the one passed in the input.
updateFinalEnv :: Trafo m t s (FinalEnv t s -> FinalEnv t s) () Source
The function updateFinalEnv
returns a Trafo
that updates the
final environment using the input function
(FinalEnv t s -> FinalEnv t s
).
Run a Trafo
runTrafo :: (forall s. Trafo m t s a (b s)) -> m () -> a -> Result m t b Source
The function runTrafo
takes as arguments the Trafo
we want to run, meta-information
for the empty environment, and an input value.
The result of runTrafo
(type Result
) is the final environment (Env t s s
) together
with the resulting meta-data (m s
), and the output value (b s
).
The rank-2 type for runTrafo
ensures that transformation steps cannot make
any assumptions about the type of final environment (s
).