HTC API Documentation
Safe HaskellSafe-Inferred

Syntax

Description

Abstract Syntax Tree (AST) definitions for the simple functional language.

Synopsis

Documentation

type Ident = String Source #

Identifier type, representing variable and function names.

data Program Source #

A program is simply a list of declarations (functions).

Constructors

Program [Decl] 

Instances

Instances details
Show Program Source # 
Instance details

Defined in Syntax

Methods

showsPrec :: Int -> Program -> ShowS

show :: Program -> String

showList :: [Program] -> ShowS

data Decl Source #

A top-level declaration consists of a function name, its parameters, and its body expression.

Constructors

FunDecl Ident [Ident] Expr 

Instances

Instances details
Show Decl Source # 
Instance details

Defined in Syntax

Methods

showsPrec :: Int -> Decl -> ShowS

show :: Decl -> String

showList :: [Decl] -> ShowS

data Expr Source #

Expressions in the language.

Constructors

Var Ident

Variable reference

Lit Literal

Literal constant

Lambda [Ident] Expr

Lambda abstraction with parameters and body

If Expr Expr Expr

Conditional: if cond then then else else

Case Expr [(Pattern, Expr)]

Pattern matching: case expr of alternatives

Let [Decl] Expr

Local declarations and body expression

App Expr Expr

Function application

BinOp BinOperator Expr Expr

Binary operator application

UnOp UnOperator Expr

Unary operator application

List [Expr]

List literal

Tuple [Expr]

Tuple literal

Instances

Instances details
Show Expr Source # 
Instance details

Defined in Syntax

Methods

showsPrec :: Int -> Expr -> ShowS

show :: Expr -> String

showList :: [Expr] -> ShowS

data Pattern Source #

Patterns used in case alternatives.

Constructors

PWildcard

Matches anything ("_" pattern)

PVar Ident

Variable pattern, binds the identifier

PLit Literal

Literal pattern

PList [Pattern]

List pattern

PTuple [Pattern]

Tuple pattern

Instances

Instances details
Show Pattern Source # 
Instance details

Defined in Syntax

Methods

showsPrec :: Int -> Pattern -> ShowS

show :: Pattern -> String

showList :: [Pattern] -> ShowS

data Literal Source #

Literal values supported by the language.

Constructors

LInt Int

Integer literal

LFloat Double

Floating-point literal

LChar Char

Character literal

LString String

String literal

LBool Bool

Boolean literal

Instances

Instances details
Show Literal Source # 
Instance details

Defined in Syntax

Methods

showsPrec :: Int -> Literal -> ShowS

show :: Literal -> String

showList :: [Literal] -> ShowS

data BinOperator Source #

Binary operators.

Constructors

Add

Addition (+)

Sub

Subtraction (-)

Mul

Multiplication (*)

Div

Division (/)

Mod

Modulus (mod)

Eq

Equality (==)

Neq

Inequality (/=)

Lt

Less than (<)

Le

Less than or equal (<=)

Gt

Greater than (>)

Ge

Greater than or equal (>=)

And

Logical and (&&)

Or

Logical or (||)

Instances

Instances details
Show BinOperator Source # 
Instance details

Defined in Syntax

Methods

showsPrec :: Int -> BinOperator -> ShowS

show :: BinOperator -> String

showList :: [BinOperator] -> ShowS

data UnOperator Source #

Unary operators.

Constructors

Neg

Numeric negation (n -> -n)

Not

Logical negation (not)

Instances

Instances details
Show UnOperator Source # 
Instance details

Defined in Syntax

Methods

showsPrec :: Int -> UnOperator -> ShowS

show :: UnOperator -> String

showList :: [UnOperator] -> ShowS