Skip to content

Functional Programming

Andrew Johnson edited this page Jan 30, 2025 · 11 revisions

Functional Programming is supported within the compiler internals based on the semantics of System F<: with Specialization. When using functional programming in applied contexts it often becomes necessary to use a variety of data structures that may have runtime costs.

Functions

Functions in LM are not limited to the ALGOL "let's put it on the stack" style of programming. Instead, LM Functions are treated as traditional mathematical objects: i.e. a set of pairs (a,b) that map domain objects to range objects.

However, in practice, compilers still need a finitary representation so we use Terms and Fragments.

  • Terms are traditional functions or expressions, no surprise here
  • A fragment is a key-value map of Strings to S-Expressions.

Between these two representations, we find that most mathematical ideas can be expressed naturally and efficiently.

Closures

Evaluation Order

LM is not explicitly eager or lazy, it just generates code to follow whatever pattern you ask for. The compiler itself is eager, but that doesn't mean your code needs to be the same.

Gradual Typing