Safe Haskell | None |
---|---|
Language | Haskell2010 |
Generic representation of typed syntax trees
For details, see: A Generic Abstract Syntax Model for Embedded Languages (ICFP 2012, http://www.cse.chalmers.se/~emax/documents/axelsson2012generic.pdf).
- data AST sym sig where
- type ASTF sym a = AST sym (Full a)
- newtype ASTFull sym a = ASTFull {}
- newtype Full a = Full {
- result :: a
- newtype a :-> sig = Partial (a -> sig)
- data SigRep sig where
- class Signature sig where
- type family DenResult sig
- class Symbol sym where
- size :: AST sym sig -> Int
- type family SmartFun (sym :: * -> *) sig
- type family SmartSig f
- type family SmartSym f :: * -> *
- smartSym' :: forall sig f sym. (Signature sig, f ~ SmartFun sym sig, sig ~ SmartSig f, sym ~ SmartSym f) => sym sig -> f
- data (sym1 :+: sym2) sig where
- class Project sub sup where
- class Project sub sup => sub :<: sup where
- smartSym :: (Signature sig, f ~ SmartFun sup sig, sig ~ SmartSig f, sup ~ SmartSym f, sub :<: sup) => sub sig -> f
- smartSymTyped :: (Signature sig, f ~ SmartFun (Typed sup) sig, sig ~ SmartSig f, Typed sup ~ SmartSym f, sub :<: sup, Typeable (DenResult sig)) => sub sig -> f
- data Empty :: * -> *
- data E e where
- liftE :: (forall a. e a -> b) -> E e -> b
- liftE2 :: (forall a b. e a -> e b -> c) -> E e -> E e -> c
- data EF e where
- liftEF :: (forall a. e (Full a) -> b) -> EF e -> b
- liftEF2 :: (forall a b. e (Full a) -> e (Full b) -> c) -> EF e -> EF e -> c
- data Typed sym sig where
- injT :: (sub :<: sup, Typeable (DenResult sig)) => sub sig -> AST (Typed sup) sig
- castExpr :: forall sym a b. ASTF (Typed sym) a -> ASTF (Typed sym) b -> Maybe (ASTF (Typed sym) b)
- class NFData1 f where
- symType :: Proxy sym -> sym sig -> sym sig
- prjP :: Project sub sup => Proxy sub -> sup sig -> Maybe (sub sig)
Syntax trees
data AST sym sig where Source #
Generic abstract syntax tree, parameterized by a symbol domain
(
represents a partially applied (or unapplied)
symbol, missing at least one argument, while AST
sym (a :->
b))(
represents a fully applied symbol, i.e. a complete syntax tree.AST
sym (Full
a))
Sym :: sym sig -> AST sym sig | |
(:$) :: AST sym (a :-> sig) -> AST sym (Full a) -> AST sym sig infixl 1 |
(:<:) sub sup => sub :<: (AST sup) Source # | |
Project sub sup => Project sub (AST sup) Source # | |
Functor sym => Functor (AST sym) Source # | |
Equality sym => Equality (AST sym) Source # | |
BindingDomain sym => BindingDomain (AST sym) Source # | |
NFData1 sym => NFData (AST sym sig) Source # | |
Syntactic (ASTF sym a) Source # | |
(Syntactic a, (~) (* -> *) (Domain a) sym, (~) * ia (Internal a), SyntacticN f fi) => SyntacticN (a -> f) (AST sym (Full ia) -> fi) Source # | |
type SmartSym (AST sym sig) Source # | |
type SmartSig (ASTF sym a -> f) Source # | |
type SmartSig (AST sym sig) Source # | |
type Domain (ASTF sym a) Source # | |
type Internal (ASTF sym a) Source # | |
newtype ASTFull sym a Source #
Fully applied abstract syntax tree
This type is like AST
, but being a newtype, it is a proper type constructor
that can be partially applied.
Signature of a fully applied symbol
Functor Full Source # | |
Eq a => Eq (Full a) Source # | |
Show a => Show (Full a) Source # | |
Signature (Full a) Source # | |
Syntactic (ASTF sym a) Source # | |
(Syntactic a, (~) (* -> *) (Domain a) sym, (~) * ia (Internal a), SyntacticN f fi) => SyntacticN (a -> f) (AST sym (Full ia) -> fi) Source # | |
type SmartFun sym (Full a) Source # | |
type DenotationM m (Full a) Source # | |
type LiftReader env (Full a) Source # | |
type DenResult (Full a) Source # | |
type Denotation (Full a) Source # | |
type LowerReader (Full a) Source # | |
type SmartSig (ASTF sym a -> f) Source # | |
type Domain (ASTF sym a) Source # | |
type Internal (ASTF sym a) Source # | |
newtype a :-> sig infixr 9 Source #
Signature of a partially applied (or unapplied) symbol
Partial (a -> sig) |
Functor ((:->) a) Source # | |
Signature sig => Signature ((:->) a sig) Source # | |
type SmartFun sym ((:->) a sig) Source # | |
type DenotationM m ((:->) a sig) Source # | |
type LiftReader env ((:->) a sig) Source # | |
type DenResult ((:->) a sig) Source # | |
type Denotation ((:->) a sig) Source # | |
type LowerReader ((:->) a sig) Source # | |
class Symbol sym where Source #
Valid symbols to use in an AST
Symbol Let Source # | |
Symbol BindingT Source # | |
Symbol Binding Source # | |
Symbol Construct Source # | |
Symbol Literal Source # | |
Symbol BindingWS Source # | |
Symbol Tuple Source # | |
Symbol (MONAD m) Source # | |
(Symbol sym1, Symbol sym2) => Symbol ((:+:) sym1 sym2) Source # | |
Symbol sym => Symbol ((:&:) sym info) Source # | |
Smart constructors
type family SmartFun (sym :: * -> *) sig Source #
Maps a symbol signature to the type of the corresponding smart constructor:
SmartFun sym (a :-> b :-> ... :-> Full x) = ASTF sym a -> ASTF sym b -> ... -> ASTF sym x
type family SmartSig f Source #
Maps a smart constructor type to the corresponding symbol signature:
SmartSig (ASTF sym a -> ASTF sym b -> ... -> ASTF sym x) = a :-> b :-> ... :-> Full x
smartSym' :: forall sig f sym. (Signature sig, f ~ SmartFun sym sig, sig ~ SmartSig f, sym ~ SmartSym f) => sym sig -> f Source #
Make a smart constructor of a symbol. smartSym'
has any type of the form:
smartSym' :: sym (a :-> b :-> ... :-> Full x) -> (ASTF sym a -> ASTF sym b -> ... -> ASTF sym x)
Open symbol domains
data (sym1 :+: sym2) sig where infixr 9 Source #
Direct sum of two symbol domains
(:<:) sym1 sym3 => sym1 :<: ((:+:) sym2 sym3) Source # | |
sym1 :<: ((:+:) sym1 sym2) Source # | |
Project sym1 sym3 => Project sym1 ((:+:) sym2 sym3) Source # | |
Project sym1 ((:+:) sym1 sym2) Source # | |
(Functor sym2, Functor sym1) => Functor ((:+:) sym1 sym2) Source # | |
(Foldable sym2, Foldable sym1) => Foldable ((:+:) sym1 sym2) Source # | |
(Traversable sym2, Traversable sym1) => Traversable ((:+:) sym1 sym2) Source # | |
(NFData1 sym1, NFData1 sym2) => NFData1 ((:+:) sym1 sym2) Source # | |
(Symbol sym1, Symbol sym2) => Symbol ((:+:) sym1 sym2) Source # | |
(StringTree sym1, StringTree sym2) => StringTree ((:+:) sym1 sym2) Source # | |
(Render sym1, Render sym2) => Render ((:+:) sym1 sym2) Source # | |
(Equality sym1, Equality sym2) => Equality ((:+:) sym1 sym2) Source # | |
(Eval s, Eval t) => Eval ((:+:) s t) Source # | |
(BindingDomain sym1, BindingDomain sym2) => BindingDomain ((:+:) sym1 sym2) Source # | |
(EvalEnv sym1 env, EvalEnv sym2 env) => EvalEnv ((:+:) sym1 sym2) env Source # | |
class Project sub sup where Source #
Symbol projection
The class is defined for all pairs of types, but prj
can only succeed if sup
is of the form
(...
.:+:
sub :+:
...)
Project sub sup Source # | |
Project sym sym Source # | |
Project sub sup => Project sub (Typed sup) Source # | |
Project sub sup => Project sub (AST sup) Source # | |
Project sym1 sym3 => Project sym1 ((:+:) sym2 sym3) Source # | |
Project sym1 ((:+:) sym1 sym2) Source # | |
Project sub sup => Project sub ((:&:) sup info) Source # | |
smartSym :: (Signature sig, f ~ SmartFun sup sig, sig ~ SmartSig f, sup ~ SmartSym f, sub :<: sup) => sub sig -> f Source #
Make a smart constructor of a symbol. smartSym
has any type of the form:
smartSym :: (sub :<: AST sup) => sub (a :-> b :-> ... :-> Full x) -> (ASTF sup a -> ASTF sup b -> ... -> ASTF sup x)
smartSymTyped :: (Signature sig, f ~ SmartFun (Typed sup) sig, sig ~ SmartSig f, Typed sup ~ SmartSym f, sub :<: sup, Typeable (DenResult sig)) => sub sig -> f Source #
Make a smart constructor of a symbol. smartSymTyped
has any type of the
form:
smartSymTyped :: (sub :<: AST (Typed sup), Typeable x) => sub (a :-> b :-> ... :-> Full x) -> (ASTF sup a -> ASTF sup b -> ... -> ASTF sup x)
Empty symbol type
Can be used to make uninhabited AST
types. It can also be used as a terminator in co-product
lists (e.g. to avoid overlapping instances):
(A :+: B :+: Empty)
Existential quantification
Type casting expressions
:: ASTF (Typed sym) a | Expression to cast |
-> ASTF (Typed sym) b | Witness for typeability of result |
-> Maybe (ASTF (Typed sym) b) |
Type cast an expression
Misc.
A class of functors that can be fully evaluated.
Since: 1.4.3.0
NFData1 [] | Since: 1.4.3.0 |
NFData1 Maybe | Since: 1.4.3.0 |
NFData1 Ratio | Available on Since: 1.4.3.0 |
NFData1 Ptr | Since: 1.4.3.0 |
NFData1 FunPtr | Since: 1.4.3.0 |
NFData1 Identity | Since: 1.4.3.0 |
NFData1 Min | Since: 1.4.3.0 |
NFData1 Max | Since: 1.4.3.0 |
NFData1 First | Since: 1.4.3.0 |
NFData1 Last | Since: 1.4.3.0 |
NFData1 WrappedMonoid | Since: 1.4.3.0 |
NFData1 Option | Since: 1.4.3.0 |
NFData1 NonEmpty | Since: 1.4.3.0 |
NFData1 Fixed | Since: 1.4.3.0 |
NFData1 StableName | Since: 1.4.3.0 |
NFData1 ZipList | Since: 1.4.3.0 |
NFData1 Dual | Since: 1.4.3.0 |
NFData1 Sum | Since: 1.4.3.0 |
NFData1 Product | Since: 1.4.3.0 |
NFData1 First | Since: 1.4.3.0 |
NFData1 Last | Since: 1.4.3.0 |
NFData1 IORef | Since: 1.4.3.0 |
NFData1 Down | Since: 1.4.3.0 |
NFData1 MVar | Since: 1.4.3.0 |
NFData1 BindingT # | |
NFData1 Binding # | |
NFData1 BindingWS # | |
NFData a => NFData1 (Either a) | Since: 1.4.3.0 |
NFData a => NFData1 ((,) a) | Since: 1.4.3.0 |
NFData a => NFData1 (Array a) | Since: 1.4.3.0 |
NFData a => NFData1 (Arg a) | Since: 1.4.3.0 |
NFData1 (Proxy *) | Since: 1.4.3.0 |
NFData1 (STRef s) | Since: 1.4.3.0 |
(NFData a1, NFData a2) => NFData1 ((,,) a1 a2) | Since: 1.4.3.0 |
NFData a => NFData1 (Const * a) | Since: 1.4.3.0 |
NFData1 ((:~:) * a) | Since: 1.4.3.0 |
(NFData1 sym1, NFData1 sym2) => NFData1 ((:+:) sym1 sym2) # | |
(NFData1 sym, NFData1 info) => NFData1 ((:&:) sym info) # | |
(NFData a1, NFData a2, NFData a3) => NFData1 ((,,,) a1 a2 a3) | Since: 1.4.3.0 |
(NFData1 f, NFData1 g) => NFData1 (Sum * f g) | Since: 1.4.3.0 |
(NFData1 f, NFData1 g) => NFData1 (Product * f g) | Since: 1.4.3.0 |
(NFData a1, NFData a2, NFData a3, NFData a4) => NFData1 ((,,,,) a1 a2 a3 a4) | Since: 1.4.3.0 |
(NFData1 f, NFData1 g) => NFData1 (Compose * * f g) | Since: 1.4.3.0 |
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5) => NFData1 ((,,,,,) a1 a2 a3 a4 a5) | Since: 1.4.3.0 |
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6) => NFData1 ((,,,,,,) a1 a2 a3 a4 a5 a6) | Since: 1.4.3.0 |
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7) => NFData1 ((,,,,,,,) a1 a2 a3 a4 a5 a6 a7) | Since: 1.4.3.0 |
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7, NFData a8) => NFData1 ((,,,,,,,,) a1 a2 a3 a4 a5 a6 a7 a8) | Since: 1.4.3.0 |