Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix := syntax in examples #35

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions example/assoc.bl
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
def (K? to V?) : (Type, Type) -> Type do:
def K? to V? : (Type, Type) -> Type =
Map of [(K, V)]

def (group pairs?) do:
def group pairs? =
match pairs with:
() => ()
x? :: y? :: xs? => (x, y) :: group xs

def (map pairs...?) do:
def map pairs...? =
Map of group pairs

def (m? find-key k?) do:
def m? find-key k? =
match m with:
(k, v?) :: xs? => v
e? :: xs? => xs find-key k

def (m? find k?) : (Any to Any, Any) -> Any do:
def m? find k? : (Any to Any, Any) -> Any =
match m with:
Map of xs? => xs find-key k

def (m? with entry?) : (Any to Any, (Any, Any)) -> Any do:
def m? with entry? : (Any to Any, (Any, Any)) -> Any =
match m with:
Map of xs? => Map of (entry :: xs)
4 changes: 3 additions & 1 deletion example/fib.bl
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Computes fib(10) recursively.

def fib (n? : Int) =
def fib n? : Int =
if n < 2 then
n
else
(fib n - 1) + (fib n - 2)

println fib 10
16 changes: 8 additions & 8 deletions example/match.bl
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
def (xs? length) do:
def xs? length =
if xs == () then 0 else 1 + (xs tail length)

def (xs? drop n?) do:
def xs? drop n? =
match n with:
0 => xs
n? => xs tail drop n - 1

def (xs? take n?) do:
def xs? take n? =
match n with:
0 => ()
n? => xs head :: xs tail take n - 1

def (merge a? b?) do:
def merge a? b? =
match (a, b) with:
(a?, ()) => a
((), b?) => b
Expand All @@ -21,14 +21,14 @@ def (merge a? b?) do:
else
b head :: (merge a b tail)

def (sort items?) do:
def sort items? =
match items with:
() => ()
x? :: () => items
xs? => do:
n := xs length
left := xs take n / 2
right := xs drop n / 2
def n = xs length
def left = xs take n / 2
def right = xs drop n / 2
merge (sort left) (sort right)

sort (list 4 7 5 2 3 0 1 9 8 6)
8 changes: 4 additions & 4 deletions example/union.bl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
def (unpack x?) do:
def unpack x? =
match x with:
i? : Int => "int!"
s? : String => "string!"

MyType := (Int | String)
x := 1 : MyType
def MyType = (Int | String)
def x = 1 : MyType

unpack x
println unpack x