The implementation of nubBy in Data.List is as follows, whereUSE_REPORT_PRELUDE refers to [1]:#ifdef USE_REPORT_PRELUDEnubBy eq [] = []nubBy eq (x:xs) = x : nubBy eq (filter (\ y -> not (eq x y)) xs)#elsenubBy eq l = nubBy' l []wherenubBy' [] _ = []nubBy' (y:ys) xs| elem_by eq y xs = nubBy' ys xs| otherwise = y : nubBy' ys (y:xs)-- Not exported:-- Note that we keep the call to `eq` with arguments in the-- same order as in the reference implementation-- 'xs' is the list of things we've seen so far,-- 'y' is the potential new elementelem_by :: (a -> a -> Bool) -> a -> [a] -> Boolelem_by _ _ [] = Falseelem_by eq y (x:xs) = y `eq` x || elem_by eq y xs#endifThat comment is actually not correct [2], and the report version and the baseversion don't have the same semantics when used on asymmetric relations:MyReportPrelude> nubBy (<) [1][1]Data.List> nubBy (<) [1,2][1,2]## ProposalMake nubBy and nub obey the report semantics by swapping the arguments to`eq` in elem_by, and defining nub as nubBy (==). This is the 'still easy'variant from [3].## MotivationThe Report's order is more sensible, since the parameters to the relation stayin the left-to-right order in which they occurred in the list. See [4,5] foruser bug reports.Discussion period: 2 weeksCode review: https://phabricator.haskell.org/D238
_______________________________________________
Libraries mailing list
Libraries@haskell.org
http://www.haskell.org/mailman/listinfo/libraries