SHARE
TWEET

Orphans

Tysonzero Oct 1st, 2019 (edited) 225 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Orphans where
  2.  
  3. data Tuple a b = Tuple a b
  4.     deriving (Eq, Show)
  5.  
  6. --
  7.  
  8. {-# LANGUAGE FlexibleInstances #-}
  9.  
  10. module OrphansFoo where
  11.  
  12. import Data.Monoid
  13. import Data.Set (Set)
  14. import qualified Data.Set as S
  15.  
  16. import Orphans
  17.  
  18. data Foo = Foo1 | Foo2
  19.     deriving (Eq, Ord, Show)
  20.  
  21. instance Ord b => Ord (Tuple Foo b) where
  22.     compare (Tuple a1 a2) (Tuple b1 b2) = compare a1 b1 <> compare a2 b2
  23.  
  24. foo :: Ord b => b -> b -> Set (Tuple Foo b)
  25. foo a b = S.fromList [Tuple Foo1 a, Tuple Foo1 b, Tuple Foo2 a, Tuple Foo2 b]
  26.  
  27. --
  28.  
  29. {-# LANGUAGE FlexibleInstances #-}
  30.  
  31. module OrphansBar where
  32.  
  33. import Data.Monoid
  34. import Data.Set (Set)
  35. import qualified Data.Set as S
  36.  
  37. import Orphans
  38.  
  39. data Bar = Bar1 | Bar2
  40.     deriving (Eq, Ord, Show)
  41.  
  42. instance Ord a => Ord (Tuple a Bar) where
  43.     compare (Tuple a1 a2) (Tuple b1 b2) = compare a2 b2 <> compare a1 b1
  44.  
  45. bar :: Ord a => a -> a -> Set (Tuple a Bar) -> Set (Tuple a Bar)
  46. bar a b s = S.fromList [Tuple a Bar1, Tuple a Bar2, Tuple b Bar1, Tuple b Bar2] <> s
  47.  
  48. --
  49.  
  50. module OrphansBaz where
  51.  
  52. import Data.Set (Set)
  53.  
  54. import Orphans
  55. import OrphansFoo
  56. import OrphansBar
  57.  
  58. baz :: Set (Tuple Foo Bar)
  59. baz = bar Foo1 Foo2 $ foo Bar1 Bar2
  60. -- fromList [Tuple Foo1 Bar1,Tuple Foo2 Bar1,Tuple Foo1 Bar2,Tuple Foo2 Bar1,Tuple Foo1 Bar2,Tuple Foo2 Bar2]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top