relation-0.2.1: A data structure representing Relations on Sets.

Portabilityportable
Stabilityexperimental
MaintainerDrew Day<drewday@gmail.com>
Safe HaskellSafe-Infered

Data.Relation.Examples.E02

Description

 

Synopsis

Documentation

p :: Show a => a -> IO ()Source

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

enrollment :: Relation [Char] [Char]Source

Example 2:

A student x can take n classes.

  • Each student must take at least 1 class
  • Each class must have at least one student.
>>> 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"])]}

rebecaenrollment :: Set [Char]Source

>>> p rebecaenrollment
fromList ["History", "Mathematics"]

takingreligion :: Set [Char]Source

>>> p takingreligion
fromList ["Rolando", "Teresa"]

others :: Set [Char]Source

>>> p others
fromList ["Architecture", "Comunication", "Religion"]

test1 :: BoolSource

>>> p test1
True

takingreligion2 :: Relation [Char] [Char]Source

>>> p takingreligion2
Relation{domain =
           fromList
             [("Rolando", fromList ["Religion"]),
              ("Teresa", fromList ["Religion"])],
         range = fromList [("Religion", fromList ["Rolando", "Teresa"])]}

id1 :: Set [Char] -> (Bool, Set [Char])Source

id2 :: Set [Char] -> (Bool, Set [Char])Source

id3 :: Set [Char] -> (Bool, Set [Char])Source

id4 :: Set [Char] -> (Bool, Set [Char])Source

teresa :: Set [Char]Source

>>> p religion
fromList ["Religion"]

t11 :: (Bool, Set [Char])Source

>>> p t11
(True, fromList ["Religion"])

t12 :: (Bool, Set [Char])Source

>>> p t12
(True, fromList ["Rolando", "Teresa"])

t13 :: (Bool, Set [Char])Source

>>> p t13
(True, fromList ["Teresa"])

t14 :: (Bool, Set [Char])Source

>>> p t14
(True, fromList ["Architecture", "Religion"])

id1R, id2R :: (Ord a, Ord b) => Set b -> Relation a b -> BoolSource

id3R, id4R :: (Ord a, Ord b) => Set a -> Relation a b -> BoolSource

testAll :: BoolSource

>>> p testAll
True