Created
November 12, 2019 13:00
-
-
Save zesterer/911e80d35c263db55f1816868c59b43c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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