relation 0.2 → 0.2.1
raw patch · 5 files changed
+224/−104 lines, 5 filesdep +groom
Dependencies added: groom
Files
- Examples/T01_Relation.hs +1/−1
- Examples/T02_Relation.hs +0/−90
- README.md +0/−0
- relation.cabal +31/−13
- src/Data/Relation/Examples/E02.hs +192/−0
Examples/T01_Relation.hs view
@@ -20,7 +20,7 @@ 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)
− Examples/T02_Relation.hs
@@ -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 - ]
+ README.md view
relation.cabal view
@@ -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 @@ 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 @@ 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++
+ src/Data/Relation/Examples/E02.hs view
@@ -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+