syntactic-1.11: Generic abstract syntax, and utilities for embedded languages

Safe HaskellNone

Language.Syntactic.Syntax

Contents

Description

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).

Synopsis

Syntax trees

data AST dom sig whereSource

Generic abstract syntax tree, parameterized by a symbol domain

(AST dom (a :-> b)) represents a partially applied (or unapplied) symbol, missing at least one argument, while (AST dom (Full a)) represents a fully applied symbol, i.e. a complete syntax tree.

Constructors

Sym :: dom sig -> AST dom sig 
:$ :: AST dom (a :-> sig) -> AST dom (Full a) -> AST dom sig 

Instances

:<: sub sup => sub :<: (AST sup) 
Project sub sup => Project sub (AST sup) 
InjectC sub sup a => InjectC sub (AST sup) a 
Functor dom => Functor (AST dom) 
Equality dom => Equality (AST dom) 
Eval dom => Eval (AST dom) 
Constrained dom => Constrained (AST dom) 
ApplySym (Full a) (ASTF dom a) dom 
Equality dom => Eq (AST dom a) 
Render dom => Show (ASTF dom a) 
Syntactic (ASTF dom a) 
(Syntactic a, ~ (* -> *) (Domain a) dom, ~ * ia (Internal a), SyntacticN b ib) => SyntacticN (a -> b) (AST dom (Full ia) -> ib) 
ApplySym sig f dom => ApplySym (:-> a sig) (ASTF dom a -> f) dom 

type ASTF dom a = AST dom (Full a)Source

Fully applied abstract syntax tree

newtype Full a Source

Signature of a fully applied symbol

Constructors

Full 

Fields

result :: a
 

Instances

Functor Full 
Typeable1 Full 
Eq a => Eq (Full a) 
Show a => Show (Full a) 
ApplySym (Full a) (ASTF dom a) dom 
Render dom => Show (ASTF dom a) 
Syntactic (ASTF dom a) 
(Syntactic a, ~ (* -> *) (Domain a) dom, ~ * ia (Internal a), SyntacticN b ib) => SyntacticN (a -> b) (AST dom (Full ia) -> ib) 
ApplySym sig f dom => ApplySym (:-> a sig) (ASTF dom a -> f) dom 

newtype a :-> sig Source

Signature of a partially applied (or unapplied) symbol

Constructors

Partial (a -> sig) 

Instances

Typeable2 :-> 
Functor (:-> a) 
ApplySym sig f dom => ApplySym (:-> a sig) (ASTF dom a -> f) dom 

size :: AST dom sig -> IntSource

Count the number of symbols in an expression

class ApplySym sig f dom | sig dom -> f, f -> sig dom whereSource

Class for the type-level recursion needed by appSym

Methods

appSym' :: AST dom sig -> fSource

Instances

ApplySym (Full a) (ASTF dom a) dom 
ApplySym sig f dom => ApplySym (:-> a sig) (ASTF dom a -> f) dom 

type family DenResult sig Source

The result type of a symbol with the given signature

Symbol domains

data (dom1 :+: dom2) a whereSource

Direct sum of two symbol domains

Constructors

InjL :: dom1 a -> (dom1 :+: dom2) a 
InjR :: dom2 a -> (dom1 :+: dom2) a 

Instances

:<: expr1 expr3 => expr1 :<: (:+: expr2 expr3) 
expr1 :<: (:+: expr1 expr2) 
Project expr1 expr3 => Project expr1 (:+: expr2 expr3) 
Project expr1 (:+: expr1 expr2) 
InjectC expr1 expr3 a => InjectC expr1 (:+: expr2 expr3) a 
InjectC expr1 (:+: expr1 expr2) a 
(Functor dom1, Functor dom2) => Functor (:+: dom1 dom2) 
(Equality expr1, Equality expr2) => Equality (:+: expr1 expr2) 
(StringTree dom1, StringTree dom2) => StringTree (:+: dom1 dom2) 
(Render expr1, Render expr2) => Render (:+: expr1 expr2) 
(Eval expr1, Eval expr2) => Eval (:+: expr1 expr2) 
Constrained (:+: sub1 sub2) 
(EvalBind sub1, EvalBind sub2) => EvalBind (:+: sub1 sub2) 
(Optimize sub1, Optimize sub2) => Optimize (:+: sub1 sub2) 
TupleSat dom2 p => TupleSat (:+: dom1 dom2) p 
TupleSat (:+: (:|| Tuple p) dom2) p 
TupleSat (:+: (:|| Select p) dom2) p 
(AlphaEq subA1 subB1 dom env, AlphaEq subA2 subB2 dom env) => AlphaEq (:+: subA1 subA2) (:+: subB1 subB2) dom env 
(Equality expr1, Equality expr2) => Eq (:+: expr1 expr2 a) 
IsHODomain (HODomain dom p pVar) p pVar 

class Project sub sup whereSource

Symbol projection

Methods

prj :: sup a -> Maybe (sub a)Source

Partial projection from sup to sub

Instances

Project expr expr 
Project sub sup => Project sub (AST sup) 
Project expr1 expr3 => Project expr1 (:+: expr2 expr3) 
Project expr1 (:+: expr1 expr2) 
Project sub sup => Project sub (:|| sup pred) 
Project sub sup => Project sub (:| sup pred) 
Project sub sup => Project sub (Decor info sup) 
Project sub sup => Project sub (SubConstr1 c sup p) 
Project sub sup => Project sub (SubConstr2 c sup pa pb) 

class Project sub sup => sub :<: sup whereSource

Symbol subsumption

Methods

inj :: sub a -> sup aSource

Injection from sub to sup

Instances

expr :<: expr 
:<: sub sup => sub :<: (AST sup) 
:<: expr1 expr3 => expr1 :<: (:+: expr2 expr3) 
expr1 :<: (:+: expr1 expr2) 

appSym :: (ApplySym sig f dom, sym :<: AST dom) => sym sig -> fSource

Generic symbol application

appSym has any type of the form:

 appSym :: (expr :<: AST dom)
     => expr (a :-> b :-> ... :-> Full x)
     -> (ASTF dom a -> ASTF dom b -> ... -> ASTF dom x)

Type inference

symType :: P sym -> sym sig -> sym sigSource

Constrain a symbol to a specific type

prjP :: Project sub sup => P sub -> sup sig -> Maybe (sub sig)Source

Projection to a specific symbol type