diff --git a/src/Errors.hs b/src/Errors.hs index 5f1b16e..5b9c28e 100644 --- a/src/Errors.hs +++ b/src/Errors.hs @@ -114,6 +114,12 @@ simplifyErrorPattern = bimap simplifyUDPattern simplifyUDPattern where (p1',p2') = if p1 == p2 then (TRUE,TRUE) else (p1,p2) (p1s',p2s') = filterSubpatterns p1s p2s + -- simplification of sequence patterns only works if there is only one + -- error, like in DaLAJ sentences + (SEQUENCE p1s,SEQUENCE p2s) -> (SEQUENCE p1s',SEQUENCE p2s') + where (p1s',p2s') = unzip $ rmCommonPost $ rmCommonPre $ p1s `zip` p2s + (SEQUENCE_ p1s,SEQUENCE_ p2s) -> (SEQUENCE_ p1s',SEQUENCE_ p2s') + where (p1s',p2s') = unzip $ rmCommonPost $ rmCommonPre $ p1s `zip` p2s ep -> ep where filterSubpatterns p1s p2s = if length p1s == length p2s diff --git a/src/Utils/Misc.hs b/src/Utils/Misc.hs index 7030943..ca9c689 100644 --- a/src/Utils/Misc.hs +++ b/src/Utils/Misc.hs @@ -15,4 +15,12 @@ rmDuplicates (x:xs) | x `elem` xs = rmDuplicates xs -- | Return all possible combinations of elements of a given list combinations :: [a] -> [[a]] -combinations xs = sequence (replicate (length xs) xs) \ No newline at end of file +combinations xs = sequence (replicate (length xs) xs) + +-- | Remove the common prefix of a zipped list +rmCommonPre :: Eq a => [(a,a)] -> [(a,a)] +rmCommonPre = dropWhile (\(p1,p2) -> p1 == p2) + +-- | Remove the common postfix of a zipped list +rmCommonPost :: Eq a => [(a,a)] -> [(a,a)] +rmCommonPost = reverse . rmCommonPre . reverse \ No newline at end of file