Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Orphans where
- data Tuple a b = Tuple a b
- deriving (Eq, Show)
- --
- {-# LANGUAGE FlexibleInstances #-}
- module OrphansFoo where
- import Data.Monoid
- import Data.Set (Set)
- import qualified Data.Set as S
- import Orphans
- data Foo = Foo1 | Foo2
- deriving (Eq, Ord, Show)
- instance Ord b => Ord (Tuple Foo b) where
- compare (Tuple a1 a2) (Tuple b1 b2) = compare a1 b1 <> compare a2 b2
- foo :: Ord b => b -> b -> Set (Tuple Foo b)
- foo a b = S.fromList [Tuple Foo1 a, Tuple Foo1 b, Tuple Foo2 a, Tuple Foo2 b]
- --
- {-# LANGUAGE FlexibleInstances #-}
- module OrphansBar where
- import Data.Monoid
- import Data.Set (Set)
- import qualified Data.Set as S
- import Orphans
- data Bar = Bar1 | Bar2
- deriving (Eq, Ord, Show)
- instance Ord a => Ord (Tuple a Bar) where
- compare (Tuple a1 a2) (Tuple b1 b2) = compare a2 b2 <> compare a1 b1
- bar :: Ord a => a -> a -> Set (Tuple a Bar) -> Set (Tuple a Bar)
- bar a b s = S.fromList [Tuple a Bar1, Tuple a Bar2, Tuple b Bar1, Tuple b Bar2] <> s
- --
- module OrphansBaz where
- import Data.Set (Set)
- import Orphans
- import OrphansFoo
- import OrphansBar
- baz :: Set (Tuple Foo Bar)
- baz = bar Foo1 Foo2 $ foo Bar1 Bar2
- -- fromList [Tuple Foo1 Bar1,Tuple Foo2 Bar1,Tuple Foo1 Bar2,Tuple Foo2 Bar1,Tuple Foo1 Bar2,Tuple Foo2 Bar2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement