Skip to content

Instantly share code, notes, and snippets.

@zesterer
Created November 12, 2019 13:00
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 zesterer/911e80d35c263db55f1816868c59b43c to your computer and use it in GitHub Desktop.
Save zesterer/911e80d35c263db55f1816868c59b43c to your computer and use it in GitHub Desktop.
# Sum types with type parameters
data Maybe T =
| Some T
| None
data Pet =
| Dog
| Cat
| Hamster
# Product types with named fields
data Person =
.name String
.age Int
.pet Maybe Pet
const bob = Person
.name "Bob"
.age 42
.pet Some Hamster
# Currying by default, equivalent to |name| |age| ...
const make_person = |name, age| Person
.name name
.age age
.pet None
# HM type inference, inferred as Int -> Int
const fibonacci = |x|
if x <= 1
then 1
else fibonacci(x - 1) + fibonacci(x - 2)
# 'universe' type used for I/O monad:
# 'print' has type String -> @ -> @, 'main' has type @ -> @
const main =
print("Hello, world!")
const quicksort = |l|
# foo:bar is infix notation for bar(foo)
let pivot = l:nth(l:len / 2);
# Operators can be curried
let (left, mid, right) = (< pivot, = pivot, > pivot)
.map(|cmp| l:filter(cmp))
[left:quicksort, mid, right:quicksort]:fuse
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment