Safe Haskell | None |
---|---|
Language | Haskell2010 |
Interpretation of tagless expressions
Synopsis
- eval :: Exp Identity a -> a
- evalF :: Exp f a -> f a
- newtype Fold e a = Fold {
- fold :: e
- class FoldN f e | f -> e where
- foldN :: e -> (e -> e -> e) -> f
- foldMonoid :: (FoldN f e, Monoid e) => f
- data (e1 :×: e2) a = (:×:) {}
- mkProd :: (lang e1, lang e2) => proxy lang -> (forall e. lang e => e a) -> (e1 :×: e2) a
- liftProd :: (lang e1, lang e2) => proxy lang -> (forall e. lang e => e a -> e b) -> (e1 :×: e2) a -> (e1 :×: e2) b
- liftProd2 :: (lang e1, lang e2) => proxy lang -> (forall e. lang e => e a -> e b -> e c) -> (e1 :×: e2) a -> (e1 :×: e2) b -> (e1 :×: e2) c
- liftProd3 :: (lang e1, lang e2) => proxy lang -> (forall e. lang e => e a -> e b -> e c -> e d) -> (e1 :×: e2) a -> (e1 :×: e2) b -> (e1 :×: e2) c -> (e1 :×: e2) d
- type BindSet = HashMap Text Int
- freshVar :: Text -> BindSet -> (Text, BindSet)
- newtype Intensional e a = Intensional {
- unIntensional :: (Fold BindSet :×: e) a
- liftIntensional :: (e a -> e b) -> Intensional e a -> Intensional e b
- liftIntensional2 :: (e a -> e b -> e c) -> Intensional e a -> Intensional e b -> Intensional e c
- liftIntensional3 :: (e a -> e b -> e c -> e d) -> Intensional e a -> Intensional e b -> Intensional e c -> Intensional e d
- class VarExp e where
- unbind :: (VarExp e, DinoType a) => Text -> (Intensional e a -> Intensional e b) -> (Text, Intensional e b)
- unbind2 :: (VarExp e, DinoType a, DinoType b) => Text -> (Intensional e a -> Intensional e b -> Intensional e c) -> (Text, Text, Intensional e c)
- class CondIntensional e where
- class ListIntensional e where
- class LetIntensional e where
- newtype NumRep = NumRep {}
- newtype Reified a = Reified {}
- appReified :: Constr -> Reified a -> Reified b
- appReified2 :: Constr -> Reified a -> Reified b -> Reified c
- appReified3 :: Constr -> Reified a -> Reified b -> Reified c -> Reified d
- appReified4 :: Constr -> Reified a -> Reified b -> Reified c -> Reified d -> Reified e
- appReified5 :: Constr -> Reified a -> Reified b -> Reified c -> Reified d -> Reified e -> Reified f
- newtype EvalEnv e a = EvalEnv {}
- extendEnv :: (Monad e, DinoType a) => Text -> a -> EvalEnv e b -> EvalEnv e b
- data EvalEnvError
- data InvalidAssertion
- = InvalidCondition { }
- | NotEqual { }
- newtype AssertViaMonadError e a = AssertViaMonadError {
- unAssertViaMonadError :: e a
- newtype AssertViaMonadThrow e a = AssertViaMonadThrow {
- unAssertViaMonadThrow :: e a
- data Assertion e where
- newtype CollectAssertions e a = CollectAssertions {
- unCollectAssertions :: Intensional (e :×: Fold [(Text, Assertion e)]) a
Type checking
Monadic interpretation
Folding
A folding interpretation
Instances of expression classes work by monoidal folding over e
(see
foldMonoid
).
Instances
class FoldN f e | f -> e where Source #
N-ary folding functions
foldMonoid :: (FoldN f e, Monoid e) => f Source #
@foldMonoid
returns an n-ary function of the following form:
\(Fold a) (Fold b) ... (Fold x) -> Fold (mempty <> a <> b <> ... x)
Product of interpretations
Product of two interpretations
The product is used to run two interpretations in parallel. Note that there
are no instances for HOS classes. Instead, use
in
order to derive an interpretation of HOS classes for products.Intensional
(e1 :×: e2)
Instances
(AnnExp ann e1, AnnExp ann e2) => AnnExp ann (e1 :×: e2 :: Type -> Type) Source # | |
(AssertExp e1, AssertExp e2) => AssertExp (e1 :×: e2) Source # | |
(FieldExp e1, FieldExp e2) => FieldExp (e1 :×: e2) Source # | |
Defined in Dino.Interpretation | |
(TupleExp e1, TupleExp e2) => TupleExp (e1 :×: e2) Source # | |
(ListExpFO e1, ListExpFO e2) => ListExpFO (e1 :×: e2) Source # | |
Defined in Dino.Interpretation | |
(CondExpFO e1, CondExpFO e2) => CondExpFO (e1 :×: e2) Source # | |
(CompareExp e1, CompareExp e2) => CompareExp (e1 :×: e2) Source # | |
Defined in Dino.Interpretation eq :: Eq a => (e1 :×: e2) a -> (e1 :×: e2) a -> (e1 :×: e2) Bool Source # neq :: Eq a => (e1 :×: e2) a -> (e1 :×: e2) a -> (e1 :×: e2) Bool Source # lt :: Ord a => (e1 :×: e2) a -> (e1 :×: e2) a -> (e1 :×: e2) Bool Source # gt :: Ord a => (e1 :×: e2) a -> (e1 :×: e2) a -> (e1 :×: e2) Bool Source # lte :: Ord a => (e1 :×: e2) a -> (e1 :×: e2) a -> (e1 :×: e2) Bool Source # gte :: Ord a => (e1 :×: e2) a -> (e1 :×: e2) a -> (e1 :×: e2) Bool Source # min :: Ord a => (e1 :×: e2) a -> (e1 :×: e2) a -> (e1 :×: e2) a Source # max :: Ord a => (e1 :×: e2) a -> (e1 :×: e2) a -> (e1 :×: e2) a Source # | |
(LogicExp e1, LogicExp e2) => LogicExp (e1 :×: e2) Source # | |
Defined in Dino.Interpretation | |
(FracExp e1, FracExp e2) => FracExp (e1 :×: e2) Source # | |
Defined in Dino.Interpretation | |
(NumExp e1, NumExp e2) => NumExp (e1 :×: e2) Source # | |
Defined in Dino.Interpretation add :: Num a => (e1 :×: e2) a -> (e1 :×: e2) a -> (e1 :×: e2) a Source # sub :: Num a => (e1 :×: e2) a -> (e1 :×: e2) a -> (e1 :×: e2) a Source # mul :: Num a => (e1 :×: e2) a -> (e1 :×: e2) a -> (e1 :×: e2) a Source # absE :: Num a => (e1 :×: e2) a -> (e1 :×: e2) a Source # signE :: Num a => (e1 :×: e2) a -> (e1 :×: e2) a Source # fromIntegral :: (Integral a, DinoType b, Num b) => (e1 :×: e2) a -> (e1 :×: e2) b Source # floor :: (RealFrac a, DinoType b, Integral b) => (e1 :×: e2) a -> (e1 :×: e2) b Source # truncate :: (RealFrac a, DinoType b, Integral b) => (e1 :×: e2) a -> (e1 :×: e2) b Source # roundN :: RealFrac a => Int -> (e1 :×: e2) a -> (e1 :×: e2) a Source # | |
(ConstExp e1, ConstExp e2) => ConstExp (e1 :×: e2) Source # | |
(LetIntensional e1, LetIntensional e2) => LetIntensional (e1 :×: e2) Source # | |
(ListIntensional e1, ListIntensional e2) => ListIntensional (e1 :×: e2) Source # | |
Defined in Dino.Interpretation mapI :: DinoType a => Text -> (e1 :×: e2) b -> (e1 :×: e2) [a] -> (e1 :×: e2) [b] Source # dropWhileI :: DinoType a => Text -> (e1 :×: e2) Bool -> (e1 :×: e2) [a] -> (e1 :×: e2) [a] Source # foldI :: (DinoType a, DinoType b) => Text -> Text -> (e1 :×: e2) a -> (e1 :×: e2) a -> (e1 :×: e2) [b] -> (e1 :×: e2) a Source # | |
(CondIntensional e1, CondIntensional e2) => CondIntensional (e1 :×: e2) Source # | |
(VarExp e1, VarExp e2) => VarExp (e1 :×: e2) Source # | |
liftProd :: (lang e1, lang e2) => proxy lang -> (forall e. lang e => e a -> e b) -> (e1 :×: e2) a -> (e1 :×: e2) b Source #
liftProd2 :: (lang e1, lang e2) => proxy lang -> (forall e. lang e => e a -> e b -> e c) -> (e1 :×: e2) a -> (e1 :×: e2) b -> (e1 :×: e2) c Source #
liftProd3 :: (lang e1, lang e2) => proxy lang -> (forall e. lang e => e a -> e b -> e c -> e d) -> (e1 :×: e2) a -> (e1 :×: e2) b -> (e1 :×: e2) c -> (e1 :×: e2) d Source #
Intensional interpretation
type BindSet = HashMap Text Int Source #
Representation of the set of variables used by bindings in an expression.
An entry (v, n)
means that the base name v
is used possibly appended with
a number that is at most n
.
Since the keys represent variable base names, they are not allowed to end with digits.
freshVar :: Text -> BindSet -> (Text, BindSet) Source #
Return an unused variable name from the given base name
The returned BindSet
includes the new variable.
newtype Intensional e a Source #
Allow intensional interpretation of higher-order constructs
Intensional
is used to obtain instances of HOS classes from their
intensional counterparts. For example, given
(
, we get
CondExpFO
e, VarExp
e, CondIntensional
e)
.CondExp
(Intensional
e)
Pairing the interpretation with a BindSet
allows generating symbolic
variables to inspect higher-order constructs rather than just running them.
Intensional | |
|
Instances
liftIntensional :: (e a -> e b) -> Intensional e a -> Intensional e b Source #
liftIntensional2 :: (e a -> e b -> e c) -> Intensional e a -> Intensional e b -> Intensional e c Source #
liftIntensional3 :: (e a -> e b -> e c -> e d) -> Intensional e a -> Intensional e b -> Intensional e c -> Intensional e d Source #
Named variable expressions
This class is only used to internally to create intensional interpretations. It should not be exposed to the EDSL user.
Instances
VarExp Reified Source # | |
VarExp e => VarExp (CollectAssertions e) Source # | |
Defined in Dino.Interpretation | |
Monad e => VarExp (EvalEnv e) Source # | Throws |
VarExp e => VarExp (Intensional e) Source # | |
Defined in Dino.Interpretation | |
Monoid e => VarExp (Fold e) Source # | |
(VarExp e1, VarExp e2) => VarExp (e1 :×: e2) Source # | |
:: (VarExp e, DinoType a) | |
=> Text | Variable base name |
-> (Intensional e a -> Intensional e b) | Body parameterized by its free variable |
-> (Text, Intensional e b) | Generated variable and function body |
Open up a binder represented as a Haskell function
This function helps creating intensional interpretations of higher-order constructs.
:: (VarExp e, DinoType a, DinoType b) | |
=> Text | Variable base name |
-> (Intensional e a -> Intensional e b -> Intensional e c) | Body parameterized by its free variables |
-> (Text, Text, Intensional e c) | Generated variables and function body |
A version of unbind
for 2-argument functions
class CondIntensional e where Source #
Intensional counterpart of CondExp
Intensional counterpart of maybe
Instances
CondIntensional Reified Source # | |
Monad e => CondIntensional (EvalEnv e) Source # | |
Semigroup e => CondIntensional (Fold e) Source # | |
(CondIntensional e1, CondIntensional e2) => CondIntensional (e1 :×: e2) Source # | |
class ListIntensional e where Source #
Intensional counterpart of ListExp
Intensional counterpart of mapE
Intensional counterpart of dropWhileE
:: (DinoType a, DinoType b) | |
=> Text | Name of state variable |
-> Text | Name of element variable |
-> e a | Body (term with two free variables) |
-> e a | |
-> e [b] | |
-> e a |
Intensional counterpart of foldE
Instances
ListIntensional Reified Source # | |
Defined in Dino.Interpretation | |
Monad e => ListIntensional (EvalEnv e) Source # | |
Defined in Dino.Interpretation | |
Semigroup e => ListIntensional (Fold e) Source # | |
(ListIntensional e1, ListIntensional e2) => ListIntensional (e1 :×: e2) Source # | |
Defined in Dino.Interpretation mapI :: DinoType a => Text -> (e1 :×: e2) b -> (e1 :×: e2) [a] -> (e1 :×: e2) [b] Source # dropWhileI :: DinoType a => Text -> (e1 :×: e2) Bool -> (e1 :×: e2) [a] -> (e1 :×: e2) [a] Source # foldI :: (DinoType a, DinoType b) => Text -> Text -> (e1 :×: e2) a -> (e1 :×: e2) a -> (e1 :×: e2) [b] -> (e1 :×: e2) a Source # |
class LetIntensional e where Source #
Intensional counterpart of LetExp
Intensional counterpart of letE
Instances
LetIntensional Reified Source # | |
Monad e => LetIntensional (EvalEnv e) Source # | |
Semigroup e => LetIntensional (Fold e) Source # | |
(LetIntensional e1, LetIntensional e2) => LetIntensional (e1 :×: e2) Source # | |
AST reification
Generic representation of numbers using Rational
Instances
Eq NumRep Source # | |
Fractional NumRep Source # | |
Num NumRep Source # | |
Ord NumRep Source # | |
Real NumRep Source # | |
Defined in Dino.Interpretation toRational :: NumRep -> Rational # | |
Show NumRep Source # | Integers are show exactly, non-integers are shown at |
Hashable NumRep Source # | |
Defined in Dino.Interpretation |
Expression reified as an AST
Instances
appReified5 :: Constr -> Reified a -> Reified b -> Reified c -> Reified d -> Reified e -> Reified f Source #
Evaluation with variables
Interpretation wrapper that evaluates using a variable environment rather than piggybacking on higher-order syntax
EvalEnv
lacks instances of HOS classes. Instead, it provides instances of
'intensional classes. In order to regain the missing HOS instances, EvalEnv
'can be wrapped in Intensional
.
is essentially equivalent to Intensional
(EvalEnv
e)e
, when e
is a
Monad
.
The purpose of EvalEnv
is to be used when evaluation must be done under
Intensional
. For example, this happens when combining reification and
evaluation.
Instances
:: (Monad e, DinoType a) | |
=> Text | Variable name |
-> a | Value of variable |
-> EvalEnv e b | Expression to evaluate in modified environment |
-> EvalEnv e b |
Add a local variable binding
data EvalEnvError Source #
Instances
Show EvalEnvError Source # | |
Defined in Dino.Interpretation showsPrec :: Int -> EvalEnvError -> ShowS # show :: EvalEnvError -> String # showList :: [EvalEnvError] -> ShowS # | |
Exception EvalEnvError Source # | |
Defined in Dino.Interpretation |
Checking assertions
data InvalidAssertion Source #
Instances
Show InvalidAssertion Source # | |
Defined in Dino.Interpretation showsPrec :: Int -> InvalidAssertion -> ShowS # show :: InvalidAssertion -> String # showList :: [InvalidAssertion] -> ShowS # | |
Exception InvalidAssertion Source # | |
Defined in Dino.Interpretation |
newtype AssertViaMonadError e a Source #
Interpretation wrapper whose AssertExp
instance uses MonadError
Instances
newtype AssertViaMonadThrow e a Source #
Interpretation wrapper whose AssertExp
instance uses MonadThrow
Instances
newtype CollectAssertions e a Source #
Collect all assertions in an expression
Note that the wrapped interpretation e
must have instances of intensional
classes in order for CollectAssertions
to derive instances of HOS classes.
In order for the wrapped interpretation to do monadic evaluation, use the
wrapper EvalEnv
to obtain the necessary intensional instances.
CollectAssertions | |
|