Advertisement
Tysonzero

Overlaps

Oct 1st, 2019
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module OverlapsFoo where
  2.  
  3. import Data.Set (Set)
  4. import qualified Data.Set as S
  5.  
  6. newtype Foo a = Foo a
  7.     deriving (Eq, Ord, Show)
  8.  
  9. mkFooSet :: Ord a => [a] -> Set (Foo a)
  10. mkFooSet = S.fromList . fmap Foo
  11.  
  12. --
  13.  
  14. {-# LANGUAGE FlexibleInstances #-}
  15.  
  16. module OverlapsBar where
  17.  
  18. import Data.Monoid
  19. import Data.Set (Set)
  20. import qualified Data.Set as S
  21.  
  22. import OverlapsFoo
  23.  
  24. data Bar = Bar1 | Bar2 | Bar3
  25.     deriving (Eq, Ord, Show)
  26.  
  27. instance {-# Overlaps #-} Ord (Foo Bar) where
  28.     compare (Foo x) (Foo y) = compare y x
  29.  
  30. bar :: Set (Foo Bar)
  31. bar = S.fromList [Foo Bar1, Foo Bar2, Foo Bar3] <> mkFooSet [Bar1, Bar2, Bar3]
  32. -- fromList [Foo Bar3,Foo Bar1,Foo Bar2,Foo Bar3,Foo Bar1]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement