Last active
October 29, 2015 21:12
-
-
Save wavebeem/889f34888598a4981215 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Good use of match | |
def compile(node) = | |
match node | |
case {type: "Add", a, b} => | |
["+", compile(a), compile(b)] | |
case {type: "If", condition, result, alternative} => | |
["if", compile(condition), compile(result), compile(alternative)] | |
# Bad use of match | |
def greet(person) = | |
match person | |
case {name, age} => | |
console.log(...) | |
# Good use of let | |
def greet(person) = | |
let {name, age} = person | |
in console.log(...) | |
# Awkward using "if" | |
def compile(node) = | |
let t = node.type | |
in if t == "Add" then | |
["+", compile(node.a), compile(node.b)] | |
else if t == "If" then | |
["if", compile(node.condition), compile(node.result), compile(node.alternative)] | |
else | |
error "Unknown node type " ++ String(t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment