[Restructuring Syntax
martin.hofmann@uni-bamberg.de**20090406145839
 Syntax.Class -> Syntax.Terms
 Syntax.Expressions from Syntax.Class
 Syntax.Patterns from Syntax.Class
 Syntax.Substitution from Syntax.Class
 
] move ./src/Syntax/Class.hs ./src/Syntax/Terms.hs
hunk ./src/Data/Rules.hs 14
-    module Syntax.Class,    
+    module Syntax.Terms,    
hunk ./src/Data/Rules.hs 31
-import Syntax.Class hiding (sameSymAt)
-import qualified Syntax.Class as T (sameSymAt)
+import Syntax.Terms hiding (sameSymAt)
+import qualified Syntax.Terms as T (sameSymAt)
hunk ./src/Rating/Rateable.hs 11
-import Syntax.Class
+import Syntax.Terms
hunk ./src/Syntax/Antiunifier.hs 22
-import Syntax.Class
+import Syntax.Terms
addfile ./src/Syntax/Expressions.hs
hunk ./src/Syntax/Expressions.hs 1
+{-# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #-}
+module Syntax.Expressions where
+
+import Language.Haskell.TH (Exp (VarE, ConE, LitE, ListE, TupE, InfixE, AppE, CondE))
+import Syntax.Terms
+import Data.Function (on)
+import qualified Data.Set as S
+import Control.Monad
+
+import Data.Maybe(maybeToList)
+
+instance Term Exp where
+
+    sameSymAtRoot (VarE _) (VarE _)                        = True
+    sameSymAtRoot (ConE n1) (ConE n2)                      = n1 == n2
+    sameSymAtRoot (LitE l1) (LitE l2)                      = l1 == l2
+    sameSymAtRoot (TupE v1s)(TupE v2s)                     = on (==) length  v1s v2s
+    sameSymAtRoot t1@(AppE _ _ ) t2@(AppE _ _ )            = on (==) (head.unfoldAppE) t1 t2
+    sameSymAtRoot (ListE []) (ListE [])                    = True
+    sameSymAtRoot (ListE _)  (ListE [])                    = False
+    sameSymAtRoot (ListE []) (ListE _)                     = False
+    sameSymAtRoot (ListE _) (ListE _)                      = True
+    sameSymAtRoot (CondE c1 t1 e1) (CondE c2 t2 e2)        = True     
+    sameSymAtRoot (InfixE _ e1 _) (InfixE _ e2 _)          = e1 == e2 
+    sameSymAtRoot  _ _                                     = False
+    
+    getPos t s | s == t     = [Root]
+               | otherwise  = 
+                    case t of
+                      (AppE e1 e2)                    -> let args = unfoldAppEargs t 
+                                                         in mapGetPos args s
+                      -- | _e is the operator (see <http://haskell.org/ghc/docs/latest/html/libraries/template-haskell/src/Language-Haskell-TH-Syntax.html#Exp>)
+                      (InfixE Nothing _e Nothing)     -> []
+                      (InfixE (Just e1) _e Nothing)   -> map (°0) (getPos e1 s)
+                      (InfixE Nothing _e (Just e2))   -> map (°1) (getPos e2 s)
+                      (InfixE (Just e1) _e (Just e2)) -> 
+                            let pos1 = map (°0) (getPos e1 s)
+                                pos2 = map (°1) (getPos e2 s)
+                            in pos1 ++ pos2
+                      (ListE [])                      -> [Root ° 0]
+                      (ListE (e1:es))                 -> mapGetPos [e1, ListE es] s  -- I HATE SYNTACTIC SUGAR!!!
+                      (TupE es)                       -> mapGetPos es s                                    
+                      _owise                          -> [] --  VarE Name, ConE Name, LitE Lit          
+                      -- These parts of the TH syntax are ignored:                      
+                      --LamE [Pat] Exp  
+                      --CondE Exp Exp Exp   
+                      --LetE [Dec] Exp  
+                      --CaseE Exp [Match]   
+                      --DoE [Stmt]  
+                      --CompE [Stmt]    
+                      --ArithSeqE Range 
+                      --SigE Exp Type   
+                      --RecConE Name [FieldExp] 
+                      --RecUpdE Exp [FieldExp]
+              
+    substitute s Root _ = s
+    substitute s pos t =
+        case pos of
+            (P i)     -> maybe t id $  moveToSubtermE t i (Just.(substitute s Root))
+            (Dot p i) -> maybe t id $  moveToSubtermE t i (Just.(substitute s p))
+            
+    subterms (VarE _)                        = []
+    subterms (ConE _)                        = []
+    subterms (LitE _)                        = []
+    subterms (TupE vals)                     = vals
+    subterms t@(AppE _ _ )                   = unfoldAppEargs t
+    subterms (ListE [])                      = []
+    subterms (ListE (l:ls))                  = [l, ListE ls] 
+    subterms (CondE e1 e2 e3)                = [e1, e2, e3]    
+    subterms (InfixE (Just e1) e2 (Just e3)) = [e1, e2, e3]
+    subterms (InfixE Nothing e2 (Just e3))   = [hole, e2, e3]
+    subterms (InfixE (Just e1) e2 Nothing)   = [e1, e2, hole]
+    subterms (InfixE Nothing e2 Nothing)     = [hole, e2, hole]
+    subterms    e                            = 
+        error $ "Terms.subterms: Not implemented for Expression " ++ (show e)
+            
+    varAtPos t p = 
+        case subtermAt t p of
+            Just (VarE _) -> True
+            _owise        -> False
+            
+    getVars_ done t@(VarE _)                      = S.insert t done
+    getVars_ done (ConE _)                        = done
+    getVars_ done (LitE _)                        = done
+    getVars_ done (TupE vals)                     = 
+        S.unions (done:(map (getVars_ S.empty) vals))
+    getVars_ done (AppE a1 a2)                    = 
+        S.unions (done:(map (getVars_ S.empty) [a1,a2]))                                                        
+    getVars_ done (ListE l)                       = 
+        S.unions (done:(map (getVars_ S.empty) l))
+    getVars_ done (CondE e1 e2 e3)                = 
+        S.unions (done:(map (getVars_ S.empty) [e1, e2, e3]))
+    getVars_ done (InfixE e1 e2 e3)               = 
+        S.unions $ done: 
+                   (map (getVars_ S.empty) $
+                        (maybeToList e1) ++ [e2] ++ (maybeToList e3))
+                        
+    getVarNames t = map (\(VarE n) -> n)  $ getVars t
+        
+    hole = ConE 'Hole
+
+--------------------------------------------------------------------------------
+-- Auxiliary functions for 'Exp' as 'Term's
+--------------------------------------------------------------------------------
+
+-- | Returns only the arguments of an 'AppE'xpression.
+unfoldAppEargs = tail . unfoldAppE
+
+-- | Peals the @Exp@s out of a @AppE@, where the first element should be the 
+--   @ConE@ of the function name or the constructor.
+unfoldAppE :: Exp -> [Exp]
+unfoldAppE e = f [] e
+    where 
+    f done e =
+        case e of
+            (AppE e1@(VarE _) e2) -> e1:e2:done
+            (AppE e1@(ConE _) e2) -> e1:e2:done
+            (AppE e1 e2)       -> f (e2:done) e1
+            _owise             -> e:done
+ 
+foldAppE :: [Exp] -> Exp
+foldAppE es = foldl1 AppE es
+
+
+-- |Moves to the specified subterm in the term @t@ and applies function @f@.
+--  The result is term @t@ with modified @i@th subterm
+--  It assures, that everything is put back at place when returning the result.
+moveToSubtermE :: (Monad m) => Exp -> Int -> (Exp -> m Exp) -> m Exp
+moveToSubtermE (VarE _) _ _ = fail "Terms.moveToSubtermE. No subterm at position"        
+moveToSubtermE (LitE _) _ _ = fail "Terms.moveToSubtermE. No subterm at position"    
+moveToSubtermE (ConE _) _ _ = fail "Terms.moveToSubtermE. No subterm at position"
+    
+moveToSubtermE t@(AppE _ _ ) i f  = do 
+    let (op:args) = (unfoldAppE t)     
+    -- the first element is the operator name
+    liftM (foldAppE.(op:)) (applyAtIndex args i f)
+    
+moveToSubtermE (TupE es) i f      = 
+   liftM TupE (applyAtIndex es i f)
+    
+moveToSubtermE (ListE (e:es)) i f = do
+    let elist = [e, ListE es]
+    [e', ListE es'] <- (applyAtIndex elist i f)
+    return $ ListE (e':es')
+    
+moveToSubtermE (InfixE (Just e1) op e2) 0 f = 
+    do { e <- f e1; return $ (InfixE (Just e) op e2)}
+moveToSubtermE (InfixE e1 op (Just e2)) 1 f = 
+    do { e <- f e2; return $ (InfixE e1 op (Just e))}
+moveToSubtermE (InfixE _ op _ ) i _          = 
+    fail $ "Terms.moveToSubtermE: No subterm at position " ++ (show i) ++ 
+           " of operator " ++ (show op)
+                                    
+
+--compareAtRootE :: Exp -> Exp -> Bool
+--compareAtRootE (VarE _) (VarE _)                        = True
+--compareAtRootE (ConE n1) (ConE n2)                      = n1 == n2
+--compareAtRootE (LitE l1) (LitE l2)                      = l1 == l2
+--compareAtRootE (TupE v1s)(TupE v2s)                     = (length v1s) == (length v2s)
+--compareAtRootE t1@(AppE _ _ ) t2@(AppE _ _ )            = compareAtRootE (head (unfoldAppE t1))(head (unfoldAppE t2))
+--compareAtRootE (ListE []) (ListE [])                    = True
+--compareAtRootE (ListE []) (ListE _)                     = False
+--compareAtRootE (ListE _)  (ListE [])                    = False
+--compareAtRootE (ListE _)  (ListE _)                     = True
+--compareAtRootE (CondE _ _ _) (CondE _ _ _)              = True    
+--compareAtRootE (InfixE _ e1 _) (InfixE _ e2 _)          = compareAtRootE e1 e2
+--compareAtRootE  _ _                                     = False
addfile ./src/Syntax/Patterns.hs
hunk ./src/Syntax/Patterns.hs 1
-
+{-# OPTIONS_GHC -fglasgow-exts -XTemplateHaskell #-}
+module Syntax.Patterns where
+
+import Language.Haskell.TH (Pat (VarP, ConP, LitP, ListP, TupP, InfixP))
+import Syntax.Terms
+
+import qualified Data.Set as S
+        
+instance Term Pat where
+
+    sameSymAtRoot (VarP _) (VarP _)                        = True
+    sameSymAtRoot (ConP c1 _) (ConP c2 _)                  = (c1 == c2)
+    sameSymAtRoot (LitP l1) (LitP l2)                      = l1 == l2
+    sameSymAtRoot (TupP v1s)(TupP v2s)                     = (length v1s) == (length v2s)
+    sameSymAtRoot (ListP [])(ListP [])                    = True
+    sameSymAtRoot (ListP [])(ListP _ )                    = False     
+    sameSymAtRoot (ListP _ )(ListP [])                    = False     
+    sameSymAtRoot (ListP _ )(ListP _ )                    = True     
+    sameSymAtRoot (InfixP _ n1 _) (InfixP _ n2 _)         = n1 ==  n2
+    sameSymAtRoot  _ _                                    = False
+
+    getPos t s | s == t     = [Root]
+               | otherwise  = 
+                    case t of
+                      (ConP _ ps)                    -> mapGetPos ps s
+                      (InfixP p1 _ p2) -> 
+                            let pos1 = map (°0) (getPos p1 s)
+                                pos2 = map (°1) (getPos p2 s)
+                            in pos1 ++ pos2
+                      (ListP [])                      -> [Root ° 0]
+                      (ListP (p1:ps))                 -> mapGetPos [p1, ListP ps] s  -- I HATE SYNTACTIC SUGAR!!!
+                      (TupP ps)                       -> mapGetPos ps s                                    
+                      _owise                          -> [] --  VarP Name, LitP Lit 
+    
+            
+    substitute s Root _ = s
+    substitute s pos t =
+        case pos of
+            (P i)     -> maybe t id $  moveToSubtermP i t (Just.(substitute s Root))
+            (Dot p i) -> maybe t id $  moveToSubtermP i t (Just.(substitute s p))
+       
+    subterms (VarP _)         = []
+    subterms (LitP _)         = []
+    subterms (ConP _ pats)    = pats
+    subterms (InfixP p1 _ p2) = [p1,p2] 
+    subterms (ListP [])       = []
+    subterms (ListP (p:ps))   = [p, ListP ps]
+    subterms (TupP pats)      = pats
+    subterms    p                            = 
+        error $ "Terms.subterms: Not implemented for Pattern " ++ (show p)
+    
+    varAtPos t p = 
+        case subtermAt t p of
+            Just (VarP _) -> True
+            _owise        -> False
+                 
+    getVars_ done t@(VarP _)                     = S.insert t done
+    getVars_ done (LitP _)                       = done
+    getVars_ done (TupP ps)                      = 
+        S.unions (done:(map (getVars_ S.empty) ps))
+    getVars_ done (ConP _ ps)                    = 
+        S.unions (done:(map (getVars_ S.empty) ps))
+    getVars_ done (ListP l)                      = 
+        S.unions (done:(map (getVars_ S.empty) l))
+    getVars_ done (InfixP e1 _ e2)              = 
+        S.unions (done:(map (getVars_ S.empty) [e1, e2]))
+                        
+    getVarNames t = map (\(VarP n) -> n)  $ getVars t
+        
+    hole = ConP 'Hole []
+ 
+
+--------------------------------------------------------------------------------
+-- Auxiliary functions for 'Pat' as 'Term's
+--------------------------------------------------------------------------------
+
+-- |Moves to the specified subterm in the term @t@ and applies function @f@.
+--  The result is term @t@ with modified @i@th subterm
+--  It is assured, that everything is put back in place when returning the result.
+moveToSubtermP :: (Monad m) => Int -> Pat -> (Pat -> m Pat) -> m Pat
+moveToSubtermP _ (VarP _) _ = fail "Terms.moveToSubtermE. No subterm at position"        
+moveToSubtermP _ (LitP _) _ = fail "Terms.moveToSubtermE. No subterm at position"    
+moveToSubtermP i (ConP n ps) f = liftM (ConP n) (applyAtIndex ps i f)
+   
+moveToSubtermP i (TupP ps) f      = 
+    liftM TupP (applyAtIndex ps i f)
+    
+moveToSubtermP i (ListP (p:ps)) f = do
+    let plist = [p,  ListP ps]
+    [p', ListP ps'] <- (applyAtIndex plist i f)
+    return $  ListP (p':ps')
+    
+moveToSubtermP i (InfixP p1 op p2) f = do
+    [p1',p2'] <- applyAtIndex [p1,p2] i f
+    return $ (InfixP p1' op p2')
+ 
addfile ./src/Syntax/Substitution.hs
hunk ./src/Syntax/Substitution.hs 1
+
+module Syntax.Substitution where
+
+import Syntax.Terms
+import Syntax.Unifier
+
+infixr 0 <~
+(<~) :: (Term a, Term b ) => a -> b -> (a, b)
+(<~) = (,)  
+
+-- | 'a <~ b' denotes the replacement of 'a' by 'b' where usually 'a' is a 
+--   variable and 'b' is a term
+type Replacement a = (a,a)
+   
+type Substitution t = [Replacement t]
+
+insertApply :: (Eq a) =>  (Replacement a) -> (Substitution a) -> (Substitution a)
+insertApply s [] = [s]
+insertApply s@(x,v) (u@(y,w):us) 
+    | (w == x) && (y == v) = (insertApply s us)
+    | w == x               = (y <~ v):(insertApply s us)
+    | otherwise            =  u:(insertApply s us)
+
+--instance (Show a, Pretty a) => Pretty (Substitution a) where
+--    view u =  "[" ++ ((concat.(intersperse ",")) (map view u)) ++ "]"
+    
+infixr 4 @@
+(@@) :: (Substitution a) -> (Substitution a) -> (Substitution a)
+s1 @@ s2 = [(u, apply s1 t) | (u,t) <- s2 ] ++ s1
+
+--merge      :: Monad m => (Substitution a) -> (Substitution a) -> m (Substitution a)
+--merge s1 s2 = if agree then return (s1++s2) else fail "merge fails"
+-- where agree = all (\v -> apply s1 (TVar v) == apply s2 (TVar v))
+--                   (map fst s1 `intersect` map fst s2)
hunk ./src/Syntax/Terms.hs 2
-module Syntax.Class (
+module Syntax.Terms (
hunk ./src/Syntax/Terms.hs 6
-    Position(Root, P),
+    Position(..),
hunk ./src/Syntax/Terms.hs 9
+    Hole,
hunk ./src/Syntax/Terms.hs 11
-    Size(..),
+    --Size(..),
hunk ./src/Syntax/Terms.hs 14
-    unfoldAppE, foldAppE, pat2Call,
+    mapGetPos, pat2Call, applyAtIndex,
hunk ./src/Syntax/Terms.hs 22
-                           , Exp (VarE, ConE, LitE, ListE, TupE, InfixE, AppE, CondE)
-                           , Pat (VarP, ConP, LitP, ListP, TupP, InfixP) 
+                         --  , Exp (VarE, ConE, LitE, ListE, TupE, InfixE, AppE, CondE)
+                         --  , Pat (VarP, ConP, LitP, ListP, TupP, InfixP) 
hunk ./src/Syntax/Terms.hs 30
-import Data.Maybe
+import Data.Maybe (fromMaybe)
hunk ./src/Syntax/Terms.hs 65
-class Size t where
-    size :: t -> Int
-    size = size_ 0 
-    
-    size_ :: Int -> t -> Int
-    
-instance Size Exp where
-    size_ done (VarE _)             = done + 1
-    size_ done (ConE _)             = done + 1
-    size_ done (LitE _)             = done + 1
-    size_ done (TupE vals)          = sum $ (done + 1):(map size vals)
-    size_ done t@(AppE e1 e2 )      = sum $ (done + 1):(map size (unfoldAppEargs t))
-    size_ done (ListE l)            = sum $ (done + 1):(map size l)
-    size_ done (CondE e1 e2 e3)     = sum $ (done + 1):(map size [e1, e2, e3])    
-    size_ done (InfixE e1 _ e2)     = sum $ (done + 1):(map size (concatMap maybeToList[e1,e2]))
-    size_ _  e                      = 
-        error $ "Terms.Class.size: Not implemented for Expression " ++ (show e)
-
-instance Size Pat where
-    size_ done (VarP _)         = done + 1
-    size_ done (LitP _)         = done + 1
-    size_ done (ConP _ pats)    = sum $ (done + 1):(map size pats)
-    size_ done (InfixP p1 _ p2) = sum $ (done + 1):(map size [p1,p2] )
-    size_ done (ListP pats)     = sum $ (done + 1):(map size pats)
-    size_ done (TupP pats)      = sum $ (done + 1):(map size pats)
-    size_ _    p                = 
-        error $ "Terms.Class.size: Not implemented for Pattern " ++ (show p)
-
-instance Size [Pat] where
-    size_ done ps = foldr (\p d -> (size p) + d ) done ps
-    
--- testing
-
-instance Size Int where
-    size_ a b= a+b
-instance Size String where
-    size_ a b = a + length b
+--class Size t where
+--    size :: t -> Int
+--    size = size_ 0 
+--    
+--    size_ :: Int -> t -> Int
+--    
+--instance Size Exp where
+--    size_ done (VarE _)             = done + 1
+--    size_ done (ConE _)             = done + 1
+--    size_ done (LitE _)             = done + 1
+--    size_ done (TupE vals)          = sum $ (done + 1):(map size vals)
+--    size_ done t@(AppE e1 e2 )      = sum $ (done + 1):(map size (unfoldAppEargs t))
+--    size_ done (ListE l)            = sum $ (done + 1):(map size l)
+--    size_ done (CondE e1 e2 e3)     = sum $ (done + 1):(map size [e1, e2, e3])    
+--    size_ done (InfixE e1 _ e2)     = sum $ (done + 1):(map size (concatMap maybeToList[e1,e2]))
+--    size_ _  e                      = 
+--        error $ "Terms.Class.size: Not implemented for Expression " ++ (show e)
+--
+--instance Size Pat where
+--    size_ done (VarP _)         = done + 1
+--    size_ done (LitP _)         = done + 1
+--    size_ done (ConP _ pats)    = sum $ (done + 1):(map size pats)
+--    size_ done (InfixP p1 _ p2) = sum $ (done + 1):(map size [p1,p2] )
+--    size_ done (ListP pats)     = sum $ (done + 1):(map size pats)
+--    size_ done (TupP pats)      = sum $ (done + 1):(map size pats)
+--    size_ _    p                = 
+--        error $ "Terms.Class.size: Not implemented for Pattern " ++ (show p)
+--
+--instance Size [Pat] where
+--    size_ done ps = foldr (\p d -> (size p) + d ) done ps
+--    
+---- testing
+--
+--instance Size Int where
+--    size_ a b= a+b
+--instance Size String where
+--    size_ a b = a + length b
hunk ./src/Syntax/Terms.hs 220
-instance Term Exp where
-
-    sameSymAtRoot (VarE _) (VarE _)                        = True
-    sameSymAtRoot (ConE n1) (ConE n2)                      = n1 == n2
-    sameSymAtRoot (LitE l1) (LitE l2)                      = l1 == l2
-    sameSymAtRoot (TupE v1s)(TupE v2s)                     = on (==) length  v1s v2s
-    sameSymAtRoot t1@(AppE _ _ ) t2@(AppE _ _ )            = on (==) (head.unfoldAppE) t1 t2
-    sameSymAtRoot (ListE []) (ListE [])                    = True
-    sameSymAtRoot (ListE _)  (ListE [])                    = False
-    sameSymAtRoot (ListE []) (ListE _)                     = False
-    sameSymAtRoot (ListE _) (ListE _)                      = True
-    sameSymAtRoot (CondE c1 t1 e1) (CondE c2 t2 e2)        = True     
-    sameSymAtRoot (InfixE _ e1 _) (InfixE _ e2 _)          = e1 == e2 
-    sameSymAtRoot  _ _                                     = False
-    
-    getPos t s | s == t     = [Root]
-               | otherwise  = 
-                    case t of
-                      (AppE e1 e2)                    -> let args = unfoldAppEargs t 
-                                                         in mapGetPos args s
-                      -- | _e is the operator (see <http://haskell.org/ghc/docs/latest/html/libraries/template-haskell/src/Language-Haskell-TH-Syntax.html#Exp>)
-                      (InfixE Nothing _e Nothing)     -> []
-                      (InfixE (Just e1) _e Nothing)   -> map (°0) (getPos e1 s)
-                      (InfixE Nothing _e (Just e2))   -> map (°1) (getPos e2 s)
-                      (InfixE (Just e1) _e (Just e2)) -> 
-                            let pos1 = map (°0) (getPos e1 s)
-                                pos2 = map (°1) (getPos e2 s)
-                            in pos1 ++ pos2
-                      (ListE [])                      -> [Root ° 0]
-                      (ListE (e1:es))                 -> mapGetPos [e1, ListE es] s  -- I HATE SYNTACTIC SUGAR!!!
-                      (TupE es)                       -> mapGetPos es s                                    
-                      _owise                          -> [] --  VarE Name, ConE Name, LitE Lit          
-                      -- These parts of the TH syntax are ignored:                      
-                      --LamE [Pat] Exp  
-                      --CondE Exp Exp Exp   
-                      --LetE [Dec] Exp  
-                      --CaseE Exp [Match]   
-                      --DoE [Stmt]  
-                      --CompE [Stmt]    
-                      --ArithSeqE Range 
-                      --SigE Exp Type   
-                      --RecConE Name [FieldExp] 
-                      --RecUpdE Exp [FieldExp]
-              
-    substitute s Root _ = s
-    substitute s pos t =
-        case pos of
-            (P i)     -> maybe t id $  moveToSubtermE t i (Just.(substitute s Root))
-            (Dot p i) -> maybe t id $  moveToSubtermE t i (Just.(substitute s p))
-            
-    subterms (VarE _)                        = []
-    subterms (ConE _)                        = []
-    subterms (LitE _)                        = []
-    subterms (TupE vals)                     = vals
-    subterms t@(AppE _ _ )                   = unfoldAppEargs t
-    subterms (ListE [])                      = []
-    subterms (ListE (l:ls))                  = [l, ListE ls] 
-    subterms (CondE e1 e2 e3)                = [e1, e2, e3]    
-    subterms (InfixE (Just e1) e2 (Just e3)) = [e1, e2, e3]
-    subterms (InfixE Nothing e2 (Just e3))   = [hole, e2, e3]
-    subterms (InfixE (Just e1) e2 Nothing)   = [e1, e2, hole]
-    subterms (InfixE Nothing e2 Nothing)     = [hole, e2, hole]
-    subterms    e                            = 
-        error $ "Terms.subterms: Not implemented for Expression " ++ (show e)
-            
-    varAtPos t p = 
-        case subtermAt t p of
-            Just (VarE _) -> True
-            _owise        -> False
-            
-    getVars_ done t@(VarE _)                      = S.insert t done
-    getVars_ done (ConE _)                        = done
-    getVars_ done (LitE _)                        = done
-    getVars_ done (TupE vals)                     = 
-        S.unions (done:(map (getVars_ S.empty) vals))
-    getVars_ done (AppE a1 a2)                    = 
-        S.unions (done:(map (getVars_ S.empty) [a1,a2]))                                                        
-    getVars_ done (ListE l)                       = 
-        S.unions (done:(map (getVars_ S.empty) l))
-    getVars_ done (CondE e1 e2 e3)                = 
-        S.unions (done:(map (getVars_ S.empty) [e1, e2, e3]))
-    getVars_ done (InfixE e1 e2 e3)               = 
-        S.unions $ done: 
-                   (map (getVars_ S.empty) $
-                        (maybeToList e1) ++ [e2] ++ (maybeToList e3))
-                        
-    getVarNames t = map (\(VarE n) -> n)  $ getVars t
-        
-    hole = ConE 'Hole
-        
-instance Term Pat where
-
-    sameSymAtRoot (VarP _) (VarP _)                        = True
-    sameSymAtRoot (ConP c1 _) (ConP c2 _)                  = (c1 == c2)
-    sameSymAtRoot (LitP l1) (LitP l2)                      = l1 == l2
-    sameSymAtRoot (TupP v1s)(TupP v2s)                     = (length v1s) == (length v2s)
-    sameSymAtRoot (ListP [])(ListP [])                    = True
-    sameSymAtRoot (ListP [])(ListP _ )                    = False     
-    sameSymAtRoot (ListP _ )(ListP [])                    = False     
-    sameSymAtRoot (ListP _ )(ListP _ )                    = True     
-    sameSymAtRoot (InfixP _ n1 _) (InfixP _ n2 _)         = n1 ==  n2
-    sameSymAtRoot  _ _                                    = False
-
-    getPos t s | s == t     = [Root]
-               | otherwise  = 
-                    case t of
-                      (ConP _ ps)                    -> mapGetPos ps s
-                      (InfixP p1 _ p2) -> 
-                            let pos1 = map (°0) (getPos p1 s)
-                                pos2 = map (°1) (getPos p2 s)
-                            in pos1 ++ pos2
-                      (ListP [])                      -> [Root ° 0]
-                      (ListP (p1:ps))                 -> mapGetPos [p1, ListP ps] s  -- I HATE SYNTACTIC SUGAR!!!
-                      (TupP ps)                       -> mapGetPos ps s                                    
-                      _owise                          -> [] --  VarP Name, LitP Lit 
-    
-            
-    substitute s Root _ = s
-    substitute s pos t =
-        case pos of
-            (P i)     -> maybe t id $  moveToSubtermP i t (Just.(substitute s Root))
-            (Dot p i) -> maybe t id $  moveToSubtermP i t (Just.(substitute s p))
-       
-    subterms (VarP _)         = []
-    subterms (LitP _)         = []
-    subterms (ConP _ pats)    = pats
-    subterms (InfixP p1 _ p2) = [p1,p2] 
-    subterms (ListP [])       = []
-    subterms (ListP (p:ps))   = [p, ListP ps]
-    subterms (TupP pats)      = pats
-    subterms    p                            = 
-        error $ "Terms.subterms: Not implemented for Pattern " ++ (show p)
-    
-    varAtPos t p = 
-        case subtermAt t p of
-            Just (VarP _) -> True
-            _owise        -> False
-                 
-    getVars_ done t@(VarP _)                     = S.insert t done
-    getVars_ done (LitP _)                       = done
-    getVars_ done (TupP ps)                      = 
-        S.unions (done:(map (getVars_ S.empty) ps))
-    getVars_ done (ConP _ ps)                    = 
-        S.unions (done:(map (getVars_ S.empty) ps))
-    getVars_ done (ListP l)                      = 
-        S.unions (done:(map (getVars_ S.empty) l))
-    getVars_ done (InfixP e1 _ e2)              = 
-        S.unions (done:(map (getVars_ S.empty) [e1, e2]))
-                        
-    getVarNames t = map (\(VarP n) -> n)  $ getVars t
-        
-    hole = ConP 'Hole []
- 
hunk ./src/Syntax/Terms.hs 245
---------------------------------------------------------------------------------
--- Auxiliary functions for 'Exp' as 'Term's
---------------------------------------------------------------------------------
-
--- | Returns only the arguments of an 'AppE'xpression.
-unfoldAppEargs = tail . unfoldAppE
-
--- | Peals the @Exp@s out of a @AppE@, where the first element should be the 
---   @ConE@ of the function name or the constructor.
-unfoldAppE :: Exp -> [Exp]
-unfoldAppE e = f [] e
-    where 
-    f done e =
-        case e of
-            (AppE e1@(VarE _) e2) -> e1:e2:done
-            (AppE e1@(ConE _) e2) -> e1:e2:done
-            (AppE e1 e2)       -> f (e2:done) e1
-            _owise             -> e:done
- 
-foldAppE :: [Exp] -> Exp
-foldAppE es = foldl1 AppE es
-
-
--- |Moves to the specified subterm in the term @t@ and applies function @f@.
---  The result is term @t@ with modified @i@th subterm
---  It assures, that everything is put back at place when returning the result.
-moveToSubtermE :: (Monad m) => Exp -> Int -> (Exp -> m Exp) -> m Exp
-moveToSubtermE (VarE _) _ _ = fail "Terms.moveToSubtermE. No subterm at position"        
-moveToSubtermE (LitE _) _ _ = fail "Terms.moveToSubtermE. No subterm at position"    
-moveToSubtermE (ConE _) _ _ = fail "Terms.moveToSubtermE. No subterm at position"
-    
-moveToSubtermE t@(AppE _ _ ) i f  = do 
-    let (op:args) = (unfoldAppE t)     
-    -- the first element is the operator name
-    liftM (foldAppE.(op:)) (applyAtIndex args i f)
-    
-moveToSubtermE (TupE es) i f      = 
-   liftM TupE (applyAtIndex es i f)
-    
-moveToSubtermE (ListE (e:es)) i f = do
-    let elist = [e, ListE es]
-    [e', ListE es'] <- (applyAtIndex elist i f)
-    return $ ListE (e':es')
-    
-moveToSubtermE (InfixE (Just e1) op e2) 0 f = 
-    do { e <- f e1; return $ (InfixE (Just e) op e2)}
-moveToSubtermE (InfixE e1 op (Just e2)) 1 f = 
-    do { e <- f e2; return $ (InfixE e1 op (Just e))}
-moveToSubtermE (InfixE _ op _ ) i _          = 
-    fail $ "Terms.moveToSubtermE: No subterm at position " ++ (show i) ++ 
-           " of operator " ++ (show op)
-                                    
-
---compareAtRootE :: Exp -> Exp -> Bool
---compareAtRootE (VarE _) (VarE _)                        = True
---compareAtRootE (ConE n1) (ConE n2)                      = n1 == n2
---compareAtRootE (LitE l1) (LitE l2)                      = l1 == l2
---compareAtRootE (TupE v1s)(TupE v2s)                     = (length v1s) == (length v2s)
---compareAtRootE t1@(AppE _ _ ) t2@(AppE _ _ )            = compareAtRootE (head (unfoldAppE t1))(head (unfoldAppE t2))
---compareAtRootE (ListE []) (ListE [])                    = True
---compareAtRootE (ListE []) (ListE _)                     = False
---compareAtRootE (ListE _)  (ListE [])                    = False
---compareAtRootE (ListE _)  (ListE _)                     = True
---compareAtRootE (CondE _ _ _) (CondE _ _ _)              = True    
---compareAtRootE (InfixE _ e1 _) (InfixE _ e2 _)          = compareAtRootE e1 e2
---compareAtRootE  _ _                                     = False
-
---------------------------------------------------------------------------------
--- Auxiliary functions for 'Pat' as 'Term's
---------------------------------------------------------------------------------
-
--- |Moves to the specified subterm in the term @t@ and applies function @f@.
---  The result is term @t@ with modified @i@th subterm
---  It is assured, that everything is put back in place when returning the result.
-moveToSubtermP :: (Monad m) => Int -> Pat -> (Pat -> m Pat) -> m Pat
-moveToSubtermP _ (VarP _) _ = fail "Terms.moveToSubtermE. No subterm at position"        
-moveToSubtermP _ (LitP _) _ = fail "Terms.moveToSubtermE. No subterm at position"    
-moveToSubtermP i (ConP n ps) f = liftM (ConP n) (applyAtIndex ps i f)
hunk ./src/Syntax/Terms.hs 246
-moveToSubtermP i (TupP ps) f      = 
-    liftM TupP (applyAtIndex ps i f)
-    
-moveToSubtermP i (ListP (p:ps)) f = do
-    let plist = [p,  ListP ps]
-    [p', ListP ps'] <- (applyAtIndex plist i f)
-    return $  ListP (p':ps')
-    
-moveToSubtermP i (InfixP p1 op p2) f = do
-    [p1',p2'] <- applyAtIndex [p1,p2] i f
-    return $ (InfixP p1' op p2')
-    
hunk ./src/Syntax/Terms.hs 247
-pat2Call n ps = foldAppE $ (ConE n):(map pat2Exp ps)    
+pat2Call n ps = foldl1 AppE $ (ConE n):(map pat2Exp ps)    
hunk ./src/Syntax/Terms.hs 252
-pat2Exp (ConP n ps) = foldAppE $ (ConE n):(map pat2Exp ps)
+pat2Exp (ConP n ps) = foldl1 AppE $ (ConE n):(map pat2Exp ps)
hunk ./src/Syntax/Terms.hs 257
-                  " cannot be transformed into an Expression!"
+                  " cannot be transformed into an Expression!" 
hunk ./src/Syntax/Translator.hs 17
-import Syntax.Class -- for Ord Type
+import Syntax.Terms -- for Ord Type
addfile ./src/Syntax/Types.hs
hunk ./src/Syntax/Unifier.hs 21
+import Syntax.Substitution
hunk ./src/Syntax/Unifier.hs 23
-infixr 0 <~
-(<~) :: a -> b -> (a, b)
-(<~) = (,)  
-
-type Replacement a = (a,a)
---instance (Pretty a) => Pretty (Replacement a) where
---    pretty (e1,e2) = parens $ (pretty e1) <+> (text " <~ ") <+> (pretty e2)
---    prettyList s = brackets $ hsep $ map pretty s
-   
-type Substitution t = [Replacement t]
-
-insertApply :: (Eq a) =>  (Replacement a) -> (Substitution a) -> (Substitution a)
-insertApply s [] = [s]
-insertApply s@(x,v) (u@(y,w):us) 
-    | (w == x) && (y == v) = (insertApply s us)
-    | w == x               = (y <~ v):(insertApply s us)
-    | otherwise            =  u:(insertApply s us)
-
---instance (Show a, Pretty a) => Pretty (Substitution a) where
---    view u =  "[" ++ ((concat.(intersperse ",")) (map view u)) ++ "]"
-    
-    
+ 
hunk ./src/Terms.hs 3
-    module Syntax.Class,
+    module Syntax.Terms,
hunk ./src/Terms.hs 17
-import Syntax.Class
+import Syntax.Terms