Re: Status of nubOrd (Proposal #2629)

Bart Massey wrote:
1) Stick nubOrd' from my previous message into Data.List and call it a day.
I don't like it, for the simple reason that its exact strictness properties are hard to explain. Low performance hurts, too.
2) Stick (non-StopList) nubWith in Data.List. Stick nubOrd in Data.Set, implemented using nubWith.
Advantages: Provides a highly efficient, fully lazy nubOrd. Provides nubWith. Reasonable implementation.
That's nubWith :: (a -> b -> Maybe b) -> b -> [a] -> [a], right? I have no strong opinion about this proposal either way.
Disadvantages: Sticking nubOrd in Data.Set is weird.
That doesn't worry me much. We can always add a link to the documentation of 'nub'. All in all I must say that the design space for nub functions is surprisingly big. One aspect that hasn't been mentioned yet is special handling for finite types. For example, nubBool (True:True:False:undefined) could well return [True,False], because all possible values have been exhausted at that point. I'm not suggesting to add more functions for this - nubBool is easily expressed as nubBool = take 2 . nub regards, Bertram

Bertram Felgenhauer
Bart Massey wrote: That's nubWith :: (a -> b -> Maybe b) -> b -> [a] -> [a], right?
Yep.
All in all I must say that the design space for nub functions is surprisingly big. One aspect that hasn't been mentioned yet is special handling for finite types.
We actually did talk about it a little earlier in this sprawling thread. But nubWith should handle it nicely if folks care.
nubBool = take 2 . nub
nub works fine on Bool, but you probably want nubWith for Char. Thanks much for the comments! Bart Massey bart <at> cs.pdx.edu

Am Donnerstag, 9. Oktober 2008 10:41 schrieb Bart Massey:
nubBool = take 2 . nub
nub [False,True,undefined] => _|_ but nubBool [False,True,undefined] => [False,True] right? Is this really intended? Take care. Bool has three values (False, True and _|_). This is no Agda. ;-) Best wishes, Wolfgang

Wolfgang Jeltsch wrote:
Am Donnerstag, 9. Oktober 2008 10:41 schrieb Bart Massey:
nubBool = take 2 . nub
Hmm, I wrote that.
nub [False,True,undefined] => _|_
Surely you mean False : True : _|_
but
nubBool [False,True,undefined] => [False,True]
right? Is this really intended?
Yes. It's a feature. I'm perfectly happy with nub :: [Bool] -> [Bool] ⊑ nubBool, which means that pure functions using 'nubBool' will never fail when using 'nub' instead works, because pure functions are monotonous. Most of the time, relaxing the strictness of functions is not a problem.
Take care. Bool has three values (False, True and _|_). This is no Agda. ;-)
Yes, I know. But for some reason people rarely try to actually evaluate a _|_ value, even in Haskell. ;-) Bertram
participants (3)
-
Bart Massey
-
Bertram Felgenhauer
-
Wolfgang Jeltsch