Implementation of a Functional Programming Language Jason Koenig Computer Systems Lab TJHSST 2009-2010
Introduction Creation of a functional language Both design and implementation Working Parsing Optimization Execution Todo: Multiple Files, I/O
What is a Functional Language? Two approaches: Imperative – like a recipe, or a how to. Declarative – like a mathematical formula. Functions are first class citizens Functions are like data
Design Goals Small and lightweight Core language highly portable Other functionality in standard library Easily embedded in other programs as scripting language Driven by implementation, rather than some external metric
Implementation File, Input Optimizer Executor Parser Program Output Characters Optimized Code Tree Lexical Analysis Syntax Tree Executor Tokens Bytes Parser Program Output
Sample Programs let even = {x| if x == 1 then false else odd.x-1}, odd = {x| if x == 1 then true else even.x-1} in (even.2000)
Sample Program let even = {x| if x == 1 then false else odd.x-1}, odd = {x| if x == 1 then true else even.x-1} in (even.2000)
Sample Program let compose = {f, g, x | f.(g.x)}, add2 = {a| a+2}, mult3 = {a| a*3}, mult3add6 = compose.mult3.add2 in mult3add6.5
Future Work Tail Recursion G-machine compilation of functions Language Imperative style constructs Standard Library Implementation: C for speed