diff options
author | Thomas Miedema <thomasmiedema@gmail.com> | 2014-11-07 17:38:59 +0100 |
---|---|---|
committer | Herbert Valerio Riedel <hvr@gnu.org> | 2014-11-07 17:46:34 +0100 |
commit | a2e7bbfe7656cf7dbf1af4da5c077ac0b5d41127 (patch) | |
tree | 90efbdfdcc83c31a5a0bce09b5eb650343ac7e55 /libraries/base/tests/T2528.hs | |
parent | df3b1d43cc862fe03f0724a9c0ac9e7cecdf4605 (diff) | |
download | haskell-a2e7bbfe7656cf7dbf1af4da5c077ac0b5d41127.tar.gz |
Preserve argument order to (==)/eq in nub and nubBy
This makes nub and nubBy behave as specified in the Haskell 98 Report.
This reverts 0ad9def53842e86fb292eccb810190711c42d7c5, and
fixes #3280, #7913 and #2528 (properly).
Before this change, the output of `T2528` was (4x wrong):
```
[A,B]
[1,2]
False
False
```
Reviewed By: dfeuer, ekmett, austin, hvr
Differential Revision: https://phabricator.haskell.org/D238
Diffstat (limited to 'libraries/base/tests/T2528.hs')
-rw-r--r-- | libraries/base/tests/T2528.hs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/libraries/base/tests/T2528.hs b/libraries/base/tests/T2528.hs new file mode 100644 index 0000000000..f1568db75a --- /dev/null +++ b/libraries/base/tests/T2528.hs @@ -0,0 +1,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] |