Skip to content

Instantly share code, notes, and snippets.

@wavebeem
Last active October 29, 2015 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wavebeem/889f34888598a4981215 to your computer and use it in GitHub Desktop.
Save wavebeem/889f34888598a4981215 to your computer and use it in GitHub Desktop.
# 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