summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Examples/T01_Relation.hs2
-rw-r--r--Examples/T02_Relation.hs90
-rw-r--r--README.md0
-rw-r--r--relation.cabal44
-rw-r--r--src/Data/Relation/Examples/E02.hs192
5 files changed, 224 insertions, 104 deletions
diff --git a/Examples/T01_Relation.hs b/Examples/T01_Relation.hs
index 8456b67..4c5b74b 100644
--- a/Examples/T01_Relation.hs
+++ b/Examples/T01_Relation.hs
@@ -20,7 +20,7 @@ r01 = R.fromList x1 -- construye a partir de una lista.
r02 = R.empty -- construye una relación vacía.
r03 = R.singleton 2 "c" -- construye una relación unitaria.
r04 = R.singleton 3 "i"
-r05 = R.insert 3 "i" r03
+r05 = R.insert 3 "i" r03
t01 r = putStrLn $
"size = " ++ (show $ R.size r)
diff --git a/Examples/T02_Relation.hs b/Examples/T02_Relation.hs
deleted file mode 100644
index daa2c65..0000000
--- a/Examples/T02_Relation.hs
+++ /dev/null
@@ -1,90 +0,0 @@
--- | Leonel Fonseca. 2010/nov/14.
--- Test module showing how to use Data.Relation.
-
-module T02_Relation where
-
-import Data.Relation
-import qualified Data.Set as S
-
--- | Para estar en la relación lleva
--- - Un estudiante lleva al menos una materia.
--- - Una materia al menos es llevada por un estudiante.
-
-lleva = fromList
- [ ("Rebeca" , "Historia" )
- , ("Rebeca" , "Matemática" )
- , ("Rolando", "Religión" )
- , ("Rolando", "Comunicación")
- , ("Teresa" , "Religión" )
- , ("Teresa" , "Arquitectura")
- , ("Antonio", "Historia" )
- ]
-
-rebecaLleva = (S.singleton "Rebeca" |$> ran lleva) lleva
-
-llevanReligión = (dom lleva <$| S.singleton "Religión") lleva
-
--- otros cursos para aquellos que llevan Religión
-otros = (llevanReligión |$> ran lleva) lleva
-
-prueba1 = (llevanReligión <$| ran lleva) lleva == llevanReligión
-
--- Explorando |>
-
-llevanReligión2 = lleva |> S.singleton "Religión"
-
-identidad1 s = ( v1 == v2, v1 )
- where
- v1 = (dom lleva |$> s) lleva
- v2 = ran (lleva |> s)
-
-
-identidad2 s = ( v1 == v2, v1 )
- where
- v1 = (dom lleva <$| s) lleva
- v2 = dom (lleva |> s)
-
-
--- Explorando <|
-
-identidad3 s = ( v1 == v2, v1 )
- where
- v1 = (s <$| ran lleva) lleva
- v2 = dom (s <| lleva)
-
-
-identidad4 s = ( v1 == v2, v2 )
- where
- v1 = (s |$> ran lleva) lleva
- v2 = ran (s <| lleva)
-
-
-religión = S.singleton "Religión"
-
-t11 = identidad1 religión
-
-t12 = identidad2 religión
-
-teresa = S.singleton "Teresa"
-
-t13 = identidad3 teresa
-
-t14 = identidad4 teresa
-
-
-identidad1R, identidad2R
- :: (Ord a, Ord b) => S.Set b -> Relación a b -> Bool
-
-identidad3R , identidad4R
- :: (Ord a, Ord b) => S.Set a -> Relación a b -> Bool
-
-identidad1R s r = (dom r |$> s) r == ran (r |> s)
-identidad2R s r = (dom r <$| s) r == dom (r |> s)
-identidad3R s r = (s <$| ran r) r == dom (s <| r)
-identidad4R s r = (s |$> ran r) r == ran (s <| r)
-
-probarTodas = all id [ identidad1R religión lleva
- , identidad2R religión lleva
- , identidad3R teresa lleva
- , identidad4R teresa lleva
- ]
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/README.md
diff --git a/relation.cabal b/relation.cabal
index f16f8ee..792636a 100644
--- a/relation.cabal
+++ b/relation.cabal
@@ -1,5 +1,5 @@
name: relation
-version: 0.2
+version: 0.2.1
synopsis: A data structure representing Relations on Sets.
description:
A library to model relationships between two objects that are subclasses of
@@ -20,11 +20,13 @@ description:
Changes:
.
@
- \ 2012.06.06. DD. Translated to English.
+ \ 0.2 -> 0.2.1 2012.06.07. DD. Added Doctests, Example02. Added "Text.Groom" dependency.
.
- \ 2009.11.09. LFL. Corrected the definition of delete.
+ \ 0.1 -> 0.2 2012.06.06. DD. Translated to English.
.
- \ 2009.11.26. LFL. Construction
+ \ 0.1 2009.11.09. LFL. Corrected the definition of delete.
+ .
+ \ 0.0 2009.11.26. LFL. Construction
@
.
homepage: https://www.github.com/d-day/relation/
@@ -42,21 +44,37 @@ cabal-version: >= 1.8
tested-with: GHC==7.4
extra-source-files:
- LICENSE,
- Changes.txt,
- src/Data/Relation.hs,
- Examples/T01_Relation.hs,
- Examples/T02_Relation.hs
+ LICENSE
+ README.md
+ Changes.txt
+ src/Data/Relation.hs
+ src/Data/Relation/Examples/E02.hs
+ Examples/T01_Relation.hs
library
hs-source-dirs : src
- exposed-modules: Data.Relation
- build-depends : base >= 4.2 && < 6.0,
- array >= 0.4 && < 0.5,
- containers >= 0.4 && < 0.6
+ exposed-modules: Data.Relation,
+ Data.Relation.Examples.E02
+
+ build-depends : base >= 4.2 && < 6.0,
+ array >= 0.4 && < 0.5,
+ containers >= 0.4 && < 0.6,
+-- doctest >= 0.7.0 && < 0.8,
+ groom >= 0.1.1 && < 0.2
+
+
+-- test-suite dt-examples
+-- type: exitcode-stdio-1.0
+-- hs-source-dirs: tests
+-- main-is: doctest-examples.hs
+-- ghc-options: -threaded
+-- build-depends: base >= 4.2 && < 6.0,
+-- doctest >= 0.7.0 && < 0.8
source-repository head
type: git
location: https://www.github.com/d-day/relation
+
+
diff --git a/src/Data/Relation/Examples/E02.hs b/src/Data/Relation/Examples/E02.hs
new file mode 100644
index 0000000..f1e2b3b
--- /dev/null
+++ b/src/Data/Relation/Examples/E02.hs
@@ -0,0 +1,192 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module : Data.Relation.Examples.E02
+-- Copyright : (c) DD. 2012
+-- (c) LFL. 2009
+-- License : BSD-style
+-- Maintainer : Drew Day<drewday@gmail.com>
+-- Stability : experimental
+-- Portability : portable
+--
+module Data.Relation.Examples.E02 where
+
+import Data.Relation
+import qualified Data.Set as S
+import Text.Groom
+
+
+-- |
+--
+-- 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 f = putStrLn $ groom $ f
+
+-- | 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.
+
+enrollment = fromList
+ [ ("Rebeca" , "History" )
+ , ("Rebeca" , "Mathematics" )
+ , ("Rolando", "Religion" )
+ , ("Rolando", "Comunication")
+ , ("Teresa" , "Religion" )
+ , ("Teresa" , "Architecture")
+ , ("Antonio", "History" )
+ ]
+
+-- ^
+-- >>> 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 = (S.singleton "Rebeca" |$> ran enrollment) enrollment
+-- ^
+-- >>> p rebecaenrollment
+-- fromList ["History", "Mathematics"]
+
+takingreligion = (dom enrollment <$| S.singleton "Religion") enrollment
+-- ^
+-- >>> p takingreligion
+-- fromList ["Rolando", "Teresa"]
+
+
+-- others courses for those taking religion
+others = (takingreligion |$> ran enrollment) enrollment
+-- ^
+-- >>> p others
+-- fromList ["Architecture", "Comunication", "Religion"]
+--
+
+
+
+
+
+test1 = (takingreligion <$| ran enrollment) enrollment == takingreligion
+--
+-- ^
+-- >>> p test1
+-- True
+
+-- Exploring |>
+--
+takingreligion2 = enrollment |> S.singleton "Religion"
+-- ^
+-- >>> p takingreligion2
+-- Relation{domain =
+-- fromList
+-- [("Rolando", fromList ["Religion"]),
+-- ("Teresa", fromList ["Religion"])],
+-- range = fromList [("Religion", fromList ["Rolando", "Teresa"])]}
+
+
+id1 s = ( v1 == v2, v1 )
+ where
+ v1 = (dom enrollment |$> s) enrollment
+ v2 = ran (enrollment |> s)
+
+
+id2 s = ( v1 == v2, v1 )
+ where
+ v1 = (dom enrollment <$| s) enrollment
+ v2 = dom (enrollment |> s)
+
+
+-- Exploring <|
+
+id3 s = ( v1 == v2, v1 )
+ where
+ v1 = (s <$| ran enrollment) enrollment
+ v2 = dom (s <| enrollment)
+
+
+id4 s = ( v1 == v2, v2 )
+ where
+ v1 = (s |$> ran enrollment) enrollment
+ v2 = ran (s <| enrollment)
+
+
+religion = S.singleton "Religion" -- has students
+teresa = S.singleton "Teresa" -- enrolled
+
+--
+-- ^
+-- >>> p religion
+-- fromList ["Religion"]
+
+t11 = id1 religion
+--
+-- ^
+-- >>> p t11
+-- (True, fromList ["Religion"])
+
+t12 = id2 religion
+--
+-- ^
+-- >>> p t12
+-- (True, fromList ["Rolando", "Teresa"])
+
+
+t13 = id3 teresa
+--
+-- ^
+-- >>> p t13
+-- (True, fromList ["Teresa"])
+
+t14 = id4 teresa
+--
+-- ^
+-- >>> p t14
+-- (True, fromList ["Architecture", "Religion"])
+
+
+id1R, id2R
+ :: (Ord a, Ord b) => S.Set b -> Relation a b -> Bool
+
+id3R , id4R
+ :: (Ord a, Ord b) => S.Set a -> Relation a b -> Bool
+
+id1R s r = (dom r |$> s) r == ran (r |> s)
+id2R s r = (dom r <$| s) r == dom (r |> s)
+id3R s r = (s <$| ran r) r == dom (s <| r)
+id4R s r = (s |$> ran r) r == ran (s <| r)
+
+testAll = all id [ id1R religion enrollment
+ , id2R religion enrollment
+ , id3R teresa enrollment
+ , id4R teresa enrollment
+ ]
+-- ^
+-- >>> p testAll
+-- True
+