File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,39 @@ module Haskell.Data.List where
22
33open import Haskell.Prelude
44
5+ open import Haskell.Data.Ord using (comparing)
6+
7+ open import Haskell.Law.Eq
8+ open import Haskell.Law.Equality
9+
510{-----------------------------------------------------------------------------
611 Operations
712------------------------------------------------------------------------------}
813
914partition : (a → Bool) → List a → (List a × List a)
1015partition p xs = (filter p xs , filter (not ∘ p) xs)
1116
17+ deleteBy : (a → a → Bool) → a → List a → List a
18+ deleteBy eq x ys = filter (not ∘ (eq x)) ys
19+
20+ delete : ⦃ Eq a ⦄ → a → List a → List a
21+ delete = deleteBy (_==_)
22+
23+ -- | These semantics of 'nub' assume that the 'Eq' instance
24+ -- is lawful.
25+ -- These semantics are inefficient, but good for proofs.
26+ nub : ⦃ _ : Eq a ⦄ → @0 ⦃ IsLawfulEq a ⦄ → List a → List a
27+ nub [] = []
28+ nub (x ∷ xs) = x ∷ delete x (nub xs)
29+
30+ postulate
31+ sortBy : (a → a → Ordering) → List a → List a
32+
33+ sort : ⦃ Ord a ⦄ → List a → List a
34+ sort = sortBy compare
35+
36+ sortOn : ⦃ Ord b ⦄ → (a → b) → List a → List a
37+ sortOn f =
38+ map snd
39+ ∘ sortBy (comparing fst)
40+ ∘ map (λ x → let y = f x in seq y (y , x))
You can’t perform that action at this time.
0 commit comments