| Portability | portable (GHC, Hugs) |
|---|---|
| Stability | stable |
| Maintainer | f@mazzo.li |
| Safe Haskell | Safe-Infered |
Language.ML.Syntax
Description
This module defines some datatypes to represent a minimal ML-like language, plus parsing and pretty-printing functions.
The syntax is:
program ::= declaration ';' program | expression
declaration ::= id '=' expression ';'
id ::= [a-zA-Z][a-zA-Z0-9_]*
ids ::= id+
expression ::= id
| '(' '\' ids . expression ')'
| '(' expression expression ')'
| '(' 'let' id '=' expression 'in' expression ')'
| '(' fix id . expression ')'
We'll omit parenthesis in the usual way - a b c is equivalent to (a b) c.
Example:
s = \ x y z . x z (y z); k = \ x y . x; i = \ x . x; k i;
- type Id = String
- data Expr
- type Decl = (Id, Expr)
- data Program = Program [Decl] Expr
- parseExpr :: String -> Either ParseError Expr
- parseExpr' :: FilePath -> IO (Either ParseError Expr)
- parseProgram :: String -> Either ParseError Program
- parseProgram' :: FilePath -> IO (Either ParseError Program)
- prettyExpr :: Expr -> Doc
- prettyDecl :: Decl -> Doc
- prettyProgram :: Program -> Doc
Abstract syntax tree
Data type representing lambda-calculus expressions.
A declaration (binds a certain expression to a variable). We add this abstraction on top of let so that we can write programs more easily (leaving let for local declarations).
A Program is a list of declaration and an expression
representing what the program does. Each declaration can use
previous declarations only (no mutual recursion).
Parsing
parseExpr' :: FilePath -> IO (Either ParseError Expr)Source
parseProgram' :: FilePath -> IO (Either ParseError Program)Source
Pretty printing
prettyExpr :: Expr -> DocSource
prettyDecl :: Decl -> DocSource
prettyProgram :: Program -> DocSource