-- 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: -- --
    --
  1. Associating elements
  2. --
  3. Provide efficient searches for either of the two elements.
  4. --
-- -- Since neither map nor fold are implemented, you -- must convert the structure to a list to process sequentially. module Data.Relation -- | This implementation avoids using S.Set (a,b) because -- it it is necessary to search for an item without knowing both -- D and R. -- -- In S.Set, you must know both values to search. -- -- Thus, we have are two maps to updated together. -- --
    --
  1. Always be careful with the associated set of the key.
  2. --
  3. If you union two relations, apply union to the set of values.
  4. --
  5. If you subtract, take care when handling the set of values.
  6. --
-- -- As a multi-map, each key is asscoated with a Set of values v. -- -- We do not allow the associations with the empty Set. data Relation a b -- | size r returns the number of tuples in the relation. size :: Relation a b -> Int -- | True if the relation r is the empty relation. null :: Relation a b -> Bool -- | Construct a relation with no elements. empty :: Relation a b -- | The list must be formatted like: [(k1, v1), (k2, v2),..,(kn, vn)]. fromList :: (Ord a, Ord b) => [(a, b)] -> Relation a b -- | Builds a Relation consiting of an association between: -- x and y. singleton :: a -> b -> Relation a b -- | The Relation that results from the union of two relations: -- r and s. union :: (Ord a, Ord b) => Relation a b -> Relation a b -> Relation a b -- | Union a list of relations using the empty relation. unions :: (Ord a, Ord b) => [Relation a b] -> Relation a b -- | Insert a relation x and y in the relation r -- insert :: (Ord a, Ord b) => a -> b -> Relation a b -> Relation a b -- | Delete an association in the relation. delete :: (Ord a, Ord b) => a -> b -> Relation a b -> Relation a b -- | The Set of values associated with a value in the domain. lookupDom :: Ord a => a -> Relation a b -> Maybe (Set b) -- | The Set of values associated with a value in the range. lookupRan :: Ord b => b -> Relation a b -> Maybe (Set a) -- | True if the element x exists in the domain of r . memberDom :: Ord a => a -> Relation a b -> Bool -- | True if the element exists in the range. memberRan :: Ord b => b -> Relation a b -> Bool -- | True if the relation contains the association x and -- y member :: (Ord a, Ord b) => a -> b -> Relation a b -> Bool -- | True if the relation does not contain the association -- x and y notMember :: (Ord a, Ord b) => a -> b -> Relation a b -> Bool -- | Builds a List from a Relation. toList :: Relation a b -> [(a, b)] -- | Returns the domain in the relation, as a Set, in its entirety. dom :: Relation a b -> Set a -- | Returns the range of the relation, as a Set, in its entirety. ran :: Relation a b -> Set b -- | A compact set of sets the values of which can be Just (Set x) -- or Nothing. -- -- The cases of Nothing are purged. -- -- It is similar to concat. compactSet :: Ord a => Set (Maybe (Set a)) -> Set a -- |
--   ( 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