3
module Introduction.Modules.Parameterised where
10
data List (A : Set) : Set where
12
_::_ : A -> List A -> List A
14
infixr 15 _::_ -- see 'Introduction.Operators' for information on infix
18
module Sorting {A : Set}(_<_ : A -> A -> Bool) where
20
insert : A -> List A -> List A
21
insert x nil = x :: nil
22
insert x (y :: ys) = ins (x < y)
24
ins : Bool -> List A -- local functions can do pattern matching and
25
ins true = x :: y :: ys -- be recursive
26
ins false = y :: insert x ys
28
sort : List A -> List A
30
sort (x :: xs) = insert x (sort xs)
37
_<_ : Nat -> Nat -> Bool
43
module SortNat = Sorting _<_
45
sort' : {A : Set}(_<_ : A -> A -> Bool) -> List A -> List A
46
sort' less = Sort'.sort
48
module Sort' = Sorting less
52
test = sort (suc zero :: zero :: suc (suc zero) :: nil)