Changeset [aa4f0a0fbe13d5ddaee85075421c916546d869e3] by Douglas Creager
Revision aa4f0a0fbe13d5ddaee85075421c916546d869e3,
committed by Douglas Creager
· November 17th, 2008 @ 11:21 PM
Lambdas now implemented using patterns
Lambda abstractions are now implemented using pattern matching. A lambda consists of a list of “clauses”, each of which contains a pattern and an expression. When you apply a lambda function to a value, we search for the first pattern in this list that matches the value. The corresponding expression is then used as the function body. The pattern match will create bindings for any identifiers contained in the pattern, and an environment containing these bindings is created to evaluate the lambda body in.
Currently there's no syntax (in either the Expression AST or the CSPM parser) for creating complex, multi-clause lambdas. Instead, the existing “\x @ «expression»” syntax creates a lambda with a single clause, and a tuple pattern of the lambda's formal parameters. Application creates a tuple value of the actual parameters to match against this pattern. http://github.com/hst/hst/commit...
4 changed files
-
M
cspm/src/HST/CSPM/Evaluate.hs -
M
cspm/src/HST/CSPM/Patterns.lhs -
M
cspm/src/HST/CSPM/Types.hs -
M
cspm/tests/expressions/test-lambdas.sh