Skip to content

Commit fb08343

Browse files
HeinrichApfelmusomelkonian
authored andcommitted
Add nub to Data.List
1 parent 67af3b4 commit fb08343

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

lib/Haskell/Data/List.agda

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,28 @@ open import Haskell.Prelude
44

55
open import Haskell.Data.Ord using (comparing)
66

7+
open import Haskell.Law.Eq
8+
open import Haskell.Law.Equality
9+
710
{-----------------------------------------------------------------------------
811
Operations
912
------------------------------------------------------------------------------}
1013

1114
partition : (a Bool) List a (List a × List a)
1215
partition p xs = (filter p xs , filter (not ∘ p) xs)
1316

17+
-- | Delete all occurrences of an item.
18+
-- Not part of 'Data.List'.
19+
deleteAll : ⦃ _ : Eq a ⦄ @0 ⦃ IsLawfulEq a ⦄ a List a List a
20+
deleteAll x = filter (not ∘ (x ==_))
21+
22+
-- | These semantics of 'nub' assume that the 'Eq' instance
23+
-- is lawful.
24+
-- These semantics are inefficient, but good for proofs.
25+
nub : ⦃ _ : Eq a ⦄ @0 ⦃ IsLawfulEq a ⦄ List a List a
26+
nub [] = []
27+
nub (x ∷ xs) = x ∷ deleteAll x (nub xs)
28+
1429
postulate
1530
sortBy : (a a Ordering) List a List a
1631

0 commit comments

Comments
 (0)