Unreachable branhces are removed, fixed a nasty bug in monomorphizer 😸
This commit is contained in:
parent
46a4d3d252
commit
3729278041
4 changed files with 68 additions and 16 deletions
11
sample-programs/bubble-sort.chrf
Normal file
11
sample-programs/bubble-sort.chrf
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
data List (a) where
|
||||
Cons : a -> List (a) -> List (a)
|
||||
Nil : List (a)
|
||||
|
||||
bubblesort : List (a) -> List (a)
|
||||
bubblesort xs = case xs of
|
||||
Nil => Nil
|
||||
Cons x => case x of
|
||||
Nil => Cons x Nil
|
||||
Cons y =>
|
||||
|
||||
23
sample-programs/insertion-sort.chrf
Normal file
23
sample-programs/insertion-sort.chrf
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
data List (a) where
|
||||
Nil : List (a)
|
||||
Cons : a -> List (a) -> List (a)
|
||||
|
||||
insert : Int -> List (Int) -> List (Int)
|
||||
insert x xs = case xs of
|
||||
Cons z zs => case (lt x z) of
|
||||
True => Cons x (Cons z zs)
|
||||
False => Cons z (insert x zs)
|
||||
Nil => Cons x Nil
|
||||
|
||||
insertionSort : List (Int) -> List (Int)
|
||||
insertionSort xs = case xs of
|
||||
Cons y ys => case ys of
|
||||
_ => insert y (insertionSort ys)
|
||||
Nil => xs
|
||||
Nil => Nil
|
||||
|
||||
main = head (insertionSort (Cons 5 (Cons 4 (Cons 3 (Cons 2 (Cons 1 Nil))))))
|
||||
|
||||
head xs = case xs of
|
||||
Cons x _ => x
|
||||
|
||||
|
|
@ -5,6 +5,9 @@ data Either(a b) where
|
|||
unwrapLeft x = case x of
|
||||
Left y => y
|
||||
|
||||
unwrapRight x = case x of
|
||||
Right y => y
|
||||
|
||||
wow = Left 5
|
||||
|
||||
main = unwrapLeft wow
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue