Interpreter of lazy, strongly and statically typed, functional language based mainly on Ocaml and Haskell. Created during JPP course.
It is stack project so compile it using
stack build
There are two possible modes:
-
Interpreter can read from standard input. Every line is interpreted separately but the state is kept between lines executions.
stack exec interpreter
-
Interpreter can execute one or more files. Every file is interpreted separately but the state is kept between files executions.
stack exec interpreter good/stdlib.cl good/lists.cl
Every program is made of three instruction types:
-
expression
(\x y. x + y) 1 2 ;
-
variable declaration
let f x y = x + y ;
-
type declaration
type Maybe a = Just a | Nothing ;
- Built-in types: int, bool
- Arithmetics, comparisons
- Conditional expressions
- Functions with many arguments, recursion
- Lambda expressions, partial application, higher-order functions, closures
- Handle of evaluation errors such as zero devision
- Static name binding
- Static typing
- Polymorphic and recursive algebraic types
- Multi-level pattern matching
- Type reconstruction (Damas–Hindley–Milner type system based on http://dev.stephendiehl.com/fun/006_hindley_milner.html)
- Negative numbers xd
- Syntactic sugar for lists
- Tuples
Parsing done using BNF Converter.
There are some examples in good
and bad
directory.