30 lines
No EOL
728 B
Text
30 lines
No EOL
728 B
Text
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 (revRange 1250))
|
|
|
|
head xs = case xs of
|
|
Cons x _ => x
|
|
|
|
revRange x = case x of
|
|
0 => Cons x Nil
|
|
x => Cons x (revRange (x + minusOne))
|
|
|
|
-- represents minus one :)
|
|
minusOne : Int ;
|
|
minusOne = 9223372036854775807 + 9223372036854775807 + 1; |