[Haskell-cafe] Exception for NaN

Casey McCann syntaxglitch at gmail.com
Fri May 13 23:41:34 CEST 2011


On Fri, May 13, 2011 at 4:48 PM, Luke Palmer <lrpalmer at gmail.com> wrote:
> On Thu, May 12, 2011 at 5:50 PM, Daniel Fischer
> <daniel.is.fischer at googlemail.com> wrote:
>>
>> Prelude Data.List> maximum [0,-1,0/0,-5,-6,-3,0/0,-2]
>> 0.0
>> Prelude Data.List> minimum [0,-1,0/0,-5,-6,-3,0/0,-2]
>> -2.0
>> Prelude Data.List> sort [0,-1,0/0,-5,-6,-3,0/0,-2]
>> [-6.0,-5.0,-2.0,NaN,-3.0,NaN,-1.0,0.0]
>
> Wow, that's the best example of NaN poison I've seen.

Somewhat less impressive, but would everyone expect these functions to
be equivalent up to performance characteristics?

    f :: (Eq a) => [a] -> [a]
    f = nub . concatMap (replicate 5)

    g :: (Eq a) => [a] -> [a]
    g = nub

If the answer that springs to mind is "yes, for any well-behaved
instance of Eq", well...

Bonus question: Should this function ever return False?

    h :: (Ord a) => a -> a -> Bool
    h x y = case compare x y of
        GT -> x > y
        EQ -> x == y
        LT -> x < y

- C.



More information about the Haskell-Cafe mailing list