summaryrefslogtreecommitdiff
path: root/src/tools/gftest/EqRel.hs
diff options
context:
space:
mode:
authorKrasimir Angelov <kr.angelov@gmail.com>2018-04-12 14:45:30 +0200
committerKrasimir Angelov <kr.angelov@gmail.com>2018-04-12 14:45:30 +0200
commit9a6b3b4a1f84f4071b2782ad876d4e8f9134da34 (patch)
tree950984f9636c3c3d9c11a3c65645e1ccf6b5a78a /src/tools/gftest/EqRel.hs
parent2d898e78c0f8bc097db675392f829f53ed62347b (diff)
parent4931acc36defec9cc6950829a2f3533b6bf94eb5 (diff)
Merge branch 'master' of https://github.com/GrammaticalFramework/GF
Diffstat (limited to 'src/tools/gftest/EqRel.hs')
-rw-r--r--src/tools/gftest/EqRel.hs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/tools/gftest/EqRel.hs b/src/tools/gftest/EqRel.hs
new file mode 100644
index 000000000..823900ae0
--- /dev/null
+++ b/src/tools/gftest/EqRel.hs
@@ -0,0 +1,32 @@
+module EqRel where
+
+import qualified Data.Map as M
+import Data.List ( sort )
+
+data EqRel a = Top | Classes [[a]] deriving (Eq,Ord,Show)
+
+(/\) :: (Ord a) => EqRel a -> EqRel a -> EqRel a
+Top /\ r = r
+r /\ Top = r
+Classes xss /\ Classes yss = Classes $ sort $ map sort $ concat -- maybe throw away singleton lists?
+ [ M.elems tabXs
+ | xs <- xss
+ , let tabXs = M.fromListWith (++)
+ [ (tabYs M.! x, [x])
+ | x <- xs ]
+ ]
+
+ where
+ tabYs = M.fromList [ (y,representative)
+ | ys <- yss
+ , let representative = head ys
+ , y <- ys ]
+
+basic :: (Ord a) => [a] -> EqRel Int
+basic xs = Classes $ sort $ map sort $ M.elems $ M.fromListWith (++)
+ [ (x,[i]) | (x,i) <- zip xs [0..] ]
+
+rep :: EqRel Int -> Int -> Int
+rep Top j = 0
+rep (Classes xss) j = head [ head xs | xs <- xss, j `elem` xs ]
+