-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A data structure representing Relations on Sets. -- -- A library to model relationships between two objects that are -- subclasses of Ord. -- -- Instead using a Map structure we use a two Maps that allows fast -- searching either by the key element or the value element. -- -- Each of Map is between an element and a set of values. Thus careful -- coordination of operations is required. -- -- This library lacks of extensive testing, formal testing or automated -- testing. Also in comparison to Data.Set or Data.Map (which provide the -- underlying infrastructure used) there are some missing methods. -- -- Two small examples are currently provided. -- -- Changes: -- --
-- 0.2 -> 0.2.1 2012.06.07. DD. Added Doctests, Example02. Added Text.Groom dependency. -- -- 0.1 -> 0.2 2012.06.06. DD. Translated to English. -- -- 0.1 2009.11.09. LFL. Corrected the definition of delete. -- -- 0.0 2009.11.26. LFL. Construction --@package relation @version 0.2.1 -- | Relations are modeled as assciations between two elements. -- -- Relations offer efficient search for any of the two elements. -- -- Unlike Data.Map, an element ca be associated more than once. -- -- The two purposes of this structure are: -- --
-- ( Case a |> r b ) --(|$>) :: (Ord a, Ord b) => Set a -> Set b -> Relation a b -> Set b -- |
-- (Case b <| r a) --(<$|) :: (Ord a, Ord b) => Set a -> Set b -> Relation a b -> Set a -- | Domain restriction for a relation. Modeled on z. (<|) :: (Ord a, Ord b) => Set a -> Relation a b -> Relation a b -- | Range restriction for a relation. Modeled on z. (|>) :: (Ord a, Ord b) => Relation a b -> Set b -> Relation a b instance (Show a, Show b) => Show (Relation a b) instance (Eq a, Eq b) => Eq (Relation a b) instance (Ord a, Ord b) => Ord (Relation a b) module Data.Relation.Examples.E02 -- | Documentation Tests -- -- All examples in this module are tested automatically with Doctest, and -- pretty printed with Text.Groom. -- -- This output is provided as proof of the correctness of the REPL -- (>>>) text: -- --
-- There are 12 tests, with 12 total interactions. -- Examples: 12 Tried: 12 Errors: 0 Failures: 0 --p :: Show a => a -> IO () -- | Example 2: -- -- A student x can take n classes. -- --
-- >>> p enrollment
-- Relation{domain =
-- fromList
-- [("Antonio", fromList ["History"]),
-- ("Rebeca", fromList ["History", "Mathematics"]),
-- ("Rolando", fromList ["Comunication", "Religion"]),
-- ("Teresa", fromList ["Architecture", "Religion"])],
-- range =
-- fromList
-- [("Architecture", fromList ["Teresa"]),
-- ("Comunication", fromList ["Rolando"]),
-- ("History", fromList ["Antonio", "Rebeca"]),
-- ("Mathematics", fromList ["Rebeca"]),
-- ("Religion", fromList ["Rolando", "Teresa"])]}
--
enrollment :: Relation [Char] [Char]
-- | -- >>> p rebecaenrollment -- fromList ["History", "Mathematics"] --rebecaenrollment :: Set [Char] -- |
-- >>> p takingreligion -- fromList ["Rolando", "Teresa"] --takingreligion :: Set [Char] -- |
-- >>> p others -- fromList ["Architecture", "Comunication", "Religion"] --others :: Set [Char] -- |
-- >>> p test1 -- True --test1 :: Bool -- |
-- >>> p takingreligion2
-- Relation{domain =
-- fromList
-- [("Rolando", fromList ["Religion"]),
-- ("Teresa", fromList ["Religion"])],
-- range = fromList [("Religion", fromList ["Rolando", "Teresa"])]}
--
takingreligion2 :: Relation [Char] [Char]
id1 :: Set [Char] -> (Bool, Set [Char])
id2 :: Set [Char] -> (Bool, Set [Char])
id3 :: Set [Char] -> (Bool, Set [Char])
id4 :: Set [Char] -> (Bool, Set [Char])
religion :: Set [Char]
-- | -- >>> p religion -- fromList ["Religion"] --teresa :: Set [Char] -- |
-- >>> p t11 -- (True, fromList ["Religion"]) --t11 :: (Bool, Set [Char]) -- |
-- >>> p t12 -- (True, fromList ["Rolando", "Teresa"]) --t12 :: (Bool, Set [Char]) -- |
-- >>> p t13 -- (True, fromList ["Teresa"]) --t13 :: (Bool, Set [Char]) -- |
-- >>> p t14 -- (True, fromList ["Architecture", "Religion"]) --t14 :: (Bool, Set [Char]) id1R, id2R :: (Ord a, Ord b) => Set b -> Relation a b -> Bool id3R, id4R :: (Ord a, Ord b) => Set a -> Relation a b -> Bool -- |
-- >>> p testAll -- True --testAll :: Bool