[Haskell-cafe] [Haskell] ANNOUNCE: set-monad

George Giorgidze giorgidze at gmail.com
Thu Jun 21 14:30:40 CEST 2012

Hi Derek,

Thanks for providing the executable example that demonstrates your
point. It is an interesting one. See my response below. I think it
takes us into the discussion as to what constitutes reasonable/law
abiding instances of Eq and Ord and what client code that uses Eq and
Ord instances can assume.

To give out my point in advance, Eq and Ord instances similar to yours
(i.e., those that proclaim two values as equal but at the same time
export or allow for function definitions that can observe that they
are not equal; that is, to tell them apart) not only break useful
properties of the Data.Set.Monad wrapper but they also break many
useful properties of the underlaying Data.Set, and many other standard
libraries and functions.

On 20 June 2012 04:03, Derek Elkins <derek.a.elkins at gmail.com> wrote:
> This is impressive because it's false.  The whole point of my original
> response was to justify Dan's intuition but explain why it was misled
> in this case.

No, In my opinion, it is not false. The fact that you need to wrap the
expression between fmap f and fmap g suggests that the problem is with
mapping the functions f and g and not with toList and fromList as you
suggest. See below for clarifications.

Let us concentrate on the ex4 and ex6 expressions in your code. These
two most clearly demonstrate the issue.

> import Data.Set.Monad
> data X = X Int Int deriving (Show)
> instance Eq X where
>    X a _ == X b _ = a == b
> instance Ord X where
>    compare (X a _) (X b _) = compare a b
> f (X _ b) = X b b
> g (X _ b) = X 1 b
> xs = Prelude.map (\x -> X x x) [1..5]
> ex4 = toList $ fmap f . fmap g $ fromList xs
> ex6 = toList $ fmap f . fromList . toList . fmap g $ fromList xs

print ex4 gives us [X 1 1,X 2 2,X 3 3,X 4 4,X 5 5]


print ex6 gives us [X 5 5]

More information about the Haskell-Cafe mailing list