Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
Created October 1, 2011 23:18
Show Gist options
  • Save puffnfresh/1256794 to your computer and use it in GitHub Desktop.
Save puffnfresh/1256794 to your computer and use it in GitHub Desktop.
Example of structural typing and tagged unions (variants)
data Option a = Some a | None
let addOne o = match o
case (Some x) = x.value + 1
case None = 1
// addOne's type is:
// Option {value: Number}
// These compile:
console.log (addOne (Some {
value: 100
}))
console.log (addOne None)
// These don't:
// console.log (addOne (Some {
// blah: 0
// }))
// console.log (addOne (Some {
// value: "asdf"
// }))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment