purescript-deprecated/purescript-sets

Ord instance for Set

Closed this issue · 3 comments

AKST commented

The Haskell implementation of this is something like this.

toAscList :: Set a -> [a]
toAscList = foldr (:) []

instance Ord a => Ord (Set a) where
    compare s1 s2 = compare (toAscList s1) (toAscList s2)

At the moment Array doesn't implement Ord either, so we can't just switch out toAscList for toList, so maybe that's also an issue? (Assuming the lack of an Ord instance is undesirable)

AKST commented

Oh sweet, must of missed that (I was looking at Data.Array), since it's part of a problem I'm dealing with, I'm happy to put a few pull requests together the instance (for Data.Set & Data.Maps)

Ok cool. The Prelude currently lives both there, and in the compiler repo, so for now you don't need to add a dependency.