sunroof-compiler-0.2: Monadic Javascript Compiler

Safe HaskellNone



Basic low-level types and their combinators. These are used as output of the compiler. Everything here is untypes and not supposed for public use!



type Expr = E ExprESource

Short name for instantiated expressions.

data ExprE Source

Instantiated expressions.


ExprE Expr 


data E expr Source

Plain expressions in Javascript.


Lit String

A precompiled (atomic) Javascript literal.

Var Id

A variable.

Dot expr expr Type

Field/attribute access (with type information): expr . expr :: Type

Apply expr [expr]

Function application: expr ( expr, ..., expr )

Function [Id] [Stmt]

Anonymous function with parameter names and body.


Functor E 
Foldable E 
Traversable E 
Show expr => Show (E expr) 

type Id = StringSource

Javascript identifier.

data Stmt Source

Plain Javascript statements.


AssignStmt Rhs Expr

Restricted assignment: Rhs = Expr;

DeleteStmt Expr

Delete reference delete Rhs;

ExprStmt Expr

Expression statement, for the sake of its side effects: Expr;

ReturnStmt Expr

Return statement: return Expr;

IfStmt Expr [Stmt] [Stmt]

If-Then-Else statement: if (Expr) { Stmts } else { Stmts }

WhileStmt Expr [Stmt]

While loop: while (Expr) { Stmts }

CommentStmt String

A comment in the code: String


data Type Source

Abstract types for Javascript expressions in Sunroof.



Base type like object or other primtive types.


Unit or void type. There is a effect but no value.

Fun [Type] Type

Function type: (t_1,..,t_n) -> t


data Rhs Source

A Right hand side of an assignment.


VarRhs Id

A variable

DotRhs Expr Expr

a named field

showExpr :: Bool -> Expr -> StringSource

Show an expression as compiled Javascript. The boolean argument says non-trivial arguments need parenthesis.

showStmt :: Stmt -> StringSource

Translate a statement into actual Javascript.

operator :: Id -> [Expr] -> ExprSource

Combinator to create a operator/function applied to the given arguments.

binOp :: String -> Expr -> Expr -> E ExprESource

Short-hand to create the applied binary operator/function. See operator.

uniOp :: String -> Expr -> E ExprESource

Short-hand to create the applied unary operator/function. See operator.

literal :: String -> ExprSource

Combinator to create a expression containing a literal in form of a string.

scopeForEffect :: [Stmt] -> ExprSource

Create a anonymous function to scope all effects in the given block of statement.