3 ms·
> well, filter should really be replaced by partition, because filter destroys information; use of filter requires manual negation of the boolean predicate < p,
by ridiculous_fish 10y ago
> well, filter should really be replaced by partition, because filter destroys information; use of filter requires manual negation of the boolean predicate < p, which represents duplicated information content
More seriously, `>=` is not the correct negation of `<` due to NaNs. The code as written will return a list with all NaNs removed, because NaNs are neither greater than nor less than any other number.
It's interesting that an in-place sort that uses only comparisons and swaps cannot have bugs like duplicated or removed elements, regardless of any bugs in the algorithm or comparison predicate. The "shuffle via sort by random" approach [1] is a nicely insane test case.
[1] http://javascript.about.com/library/blsort2.htm http://javascript.about.com/library/blsort2.htm
- wereHamster 10y agoYou only have to deal with NaNs if they are valid values of the type the array is made out of. In Haskell an 'Int' can not be NaN. Only types of the 'RealFloat' class can be NaN.