blob: f1568db75a4be6b1578e8041d9782fb3bf35862b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
module Main where
import qualified Data.List as L
-- USE_REPORT_PRELUDE versions of nub and nubBy, copied from
-- libraries/base/Data/OldList.hs.
nub :: (Eq a) => [a] -> [a]
nub = nubBy (==)
nubBy :: (a -> a -> Bool) -> [a] -> [a]
nubBy eq [] = []
nubBy eq (x:xs) = x : nubBy eq (filter (\ y -> not (eq x y)) xs)
data Asymmetric = A | B deriving Show
instance Eq Asymmetric where
A == _ = True
B == _ = False
main :: IO()
main = do
print $ L.nub [A,B]
print $ L.nubBy (<) [1,2]
-- The implementation from Data.List and the one from the Prelude defined in
-- the Haskell 98 report should have the same behavior.
print $ L.nub [A,B] == nub [A,B]
print $ L.nubBy (<) [1,2] == nubBy (<) [1,2]
|