Guest User

Untitled

a guest
Jul 15th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import Data.List
  2. import Control.Monad
  3.  
  4. type Subst = [(String, Formula)]
  5. (|->) :: String -> Formula -> Subst
  6. v |-> f = [(v,f)]
  7.  
  8. data Formula = Var String
  9. | FTrue | FFalse
  10. | FAnd [Formula]
  11. | FOr [Formula]
  12. | FEquiv [Formula]
  13. | Formula :=> Formula
  14. | Formula :<= Formula
  15. | Formula := Formula
  16. | Not Formula
  17. deriving (Eq,Ord)
  18.  
  19. match :: (MonadPlus m) => Formula -> Formula -> [(Formula,m Subst)]
  20. match (Var p) f = [(f, return (p |-> f))]
  21. match FFalse FFalse = [(FFalse, mzero)]
  22. match FFalse _ = []
  23. match FTrue FTrue = [(FTrue,mzero)]
  24. match FTrue _ = []
  25. match (Not f) (Not g) = map (prod Not id) $ match f g
  26. match (FAnd fs1) (FAnd fs2) = [ matchList FAnd fs1 l | l <- permutations fs2 ]
  27. match (FOr fs1) (FOr fs2) = [ matchList FOr fs1 l | l <- permutations fs2 ]
  28. match (FEquiv fs1) (FEquiv fs2) = [ matchList FEquiv fs1 l | l <- permutations fs2 ]
  29.  
  30. matchList :: (MonadPlus m) => ([Formula] -> Formula ) -> [Formula] -> [Formula] -> (Formula,m Subst)
  31. matchList cons fs1 fs2 = prod cons msum $ unzip.concat $ zipWith match fs1 fs2
  32.  
  33. prod f g (a,b) = (f a, g b)
Add Comment
Please, Sign In to add comment