Safe HaskellSafe

MosesAST

Synopsis

Documentation

type VarName = String #

Variable names

data Expr #

Moses expressions

NOTE: In the comments below, concrete Moses syntax examples are shown between braces. For example, { f 42 } is Moses concrete syntax for calling the function { f } and passing the argument { 42 }.

Constructors

Exactly Value

value (doesn't need evaluation)

For example: { 1 } is represented as Exactly (Int 1)

Var VarName

variable

For example: { x } is represented as Var "x"

Apply Expr Expr

function application

For example: { f 42 } is represented as Apply (Var "f") (Exactly (Int 42))

BinOp Op Expr Expr

built-in operator

For example: { 2+2 } is represented as BinOp Plus (Exactly (Int 2)) (Exactly (Int 2))

For example: { x @ [] } is represented as BinOp Cons (Var "x") (Exactly Nil)

If Expr Expr Expr

if statement

For example: { if a then b else c } is represented as If (Var "a") (Var "b") (Var "c")

Let [VarName] Expr Expr

let statement, handles both regular lets and tuple-match lets

For example: { let x = 2 in x + x } is represented as Let ["x"] (Exactly (Int 2)) (BinOp Plus (Var "x") (Var "x"))

For example: { let (x,y) = mypair in x+y } is represented as Let ["x","y"] (Var "mypair") (BinOp Plus (Var "x") (Var "y"))

LetRec VarName Expr Expr

recursive let statement

For example: { letrec ones = 1 : ones in ones } is represented as LetRec "ones" (BinOp Cons (Exactly (Int 1)) (Var "ones")) (Var "ones")

Lambda VarName Ty Expr

lambda expression

For example: { x :: INT -> x + 1 } is represented as Lambda "x" IntTy (BinOp Plus (Var "x") (Exactly (Int 1)))

ListCase Expr Expr VarName VarName Expr

case expression on lists

For example: { case l of [] -> 0 | h : t -> h } is represented as ListCase (Var "l") (Exactly (Int 0)) "h" "t" (Var "h")

Notice that the form is very restrictive; you cannot have case expressions where the patterns have a different structure. It must be empty list as the first case and head and tail as the second!

Tuple [Expr]

expression to create a tuple

For example: { (x,1,[]) } is represented as Tuple [Var "x",Exactly (Int 1),Exactly Nil]

Instances

Eq Expr # 

Methods

(==) :: Expr -> Expr -> Bool

(/=) :: Expr -> Expr -> Bool

Ord Expr # 

Methods

compare :: Expr -> Expr -> Ordering

(<) :: Expr -> Expr -> Bool

(<=) :: Expr -> Expr -> Bool

(>) :: Expr -> Expr -> Bool

(>=) :: Expr -> Expr -> Bool

max :: Expr -> Expr -> Expr

min :: Expr -> Expr -> Expr

Show Expr # 

Methods

showsPrec :: Int -> Expr -> ShowS

show :: Expr -> String

showList :: [Expr] -> ShowS

data Value #

Literal values

Constructors

Int Integer 
Real Double 
Str String 
Boolean Bool 
Nil 

Instances

Eq Value # 

Methods

(==) :: Value -> Value -> Bool

(/=) :: Value -> Value -> Bool

Ord Value # 

Methods

compare :: Value -> Value -> Ordering

(<) :: Value -> Value -> Bool

(<=) :: Value -> Value -> Bool

(>) :: Value -> Value -> Bool

(>=) :: Value -> Value -> Bool

max :: Value -> Value -> Value

min :: Value -> Value -> Value

Show Value # 

Methods

showsPrec :: Int -> Value -> ShowS

show :: Value -> String

showList :: [Value] -> ShowS

data Op #

Operators

Instances

Eq Op # 

Methods

(==) :: Op -> Op -> Bool

(/=) :: Op -> Op -> Bool

Ord Op # 

Methods

compare :: Op -> Op -> Ordering

(<) :: Op -> Op -> Bool

(<=) :: Op -> Op -> Bool

(>) :: Op -> Op -> Bool

(>=) :: Op -> Op -> Bool

max :: Op -> Op -> Op

min :: Op -> Op -> Op

Show Op # 

Methods

showsPrec :: Int -> Op -> ShowS

show :: Op -> String

showList :: [Op] -> ShowS

data Ty #

Built-in types

Constructors

IntTy 
RealTy 
StringTy 
BoolTy 
AnyTy 
NoneTy 
FunTy Ty Ty

Parameterized type: Function from type a to type b

TupleTy [Ty]

Parameterized type: Tuple of types t_1 to t_n

ListTy Ty

Parameterized type: List of elements of type a

Instances

Eq Ty # 

Methods

(==) :: Ty -> Ty -> Bool

(/=) :: Ty -> Ty -> Bool

Ord Ty # 

Methods

compare :: Ty -> Ty -> Ordering

(<) :: Ty -> Ty -> Bool

(<=) :: Ty -> Ty -> Bool

(>) :: Ty -> Ty -> Bool

(>=) :: Ty -> Ty -> Bool

max :: Ty -> Ty -> Ty

min :: Ty -> Ty -> Ty

Show Ty # 

Methods

showsPrec :: Int -> Ty -> ShowS

show :: Ty -> String

showList :: [Ty] -> ShowS

printParens :: Bool -> Doc -> Doc #

(<+..>) :: Doc -> Doc -> Doc infixl 6 #

(<+....>) :: Doc -> Doc -> Doc infixl 6 #

printTyPrec :: Int -> Ty -> Doc #

printExprPrec :: Int -> Expr -> Doc #

Printing expressions

printValuePrec :: Int -> Value -> Doc #

printExpr :: Expr -> Doc #

printValue :: Value -> Doc #

printTy :: Ty -> Doc #