summaryrefslogtreecommitdiff
path: root/src/GF/Speech/Relation.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/GF/Speech/Relation.hs')
-rw-r--r--src/GF/Speech/Relation.hs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/GF/Speech/Relation.hs b/src/GF/Speech/Relation.hs
index a62b4b1a7..fe91716c6 100644
--- a/src/GF/Speech/Relation.hs
+++ b/src/GF/Speech/Relation.hs
@@ -12,12 +12,13 @@
-- A simple module for relations.
-----------------------------------------------------------------------------
-module GF.Speech.Relation (Rel, mkRel
+module GF.Speech.Relation (Rel, mkRel, mkRel'
, allRelated , isRelatedTo
, transitiveClosure
, reflexiveClosure, reflexiveClosure_
, symmetricClosure
, symmetricSubrelation, reflexiveSubrelation
+ , reflexiveElements
, equivalenceClasses
, isTransitive, isReflexive, isSymmetric
, isEquivalence
@@ -38,6 +39,11 @@ type Rel a = Map a (Set a)
mkRel :: Ord a => [(a,a)] -> Rel a
mkRel ps = relates ps Map.empty
+-- | Creates a relation from a list pairs of elements and the elements
+-- related to them.
+mkRel' :: Ord a => [(a,[a])] -> Rel a
+mkRel' xs = Map.fromListWith Set.union [(x,Set.fromList ys) | (x,ys) <- xs]
+
relToList :: Rel a -> [(a,a)]
relToList r = [ (x,y) | (x,ys) <- Map.toList r, y <- Set.toList ys ]