[converting Exp <-> Pat, Bugfix in subterms
martin.hofmann@uni-bamberg.de**20090218091718] hunk ./src/Terms/Class.hs 13
-    unfoldAppE, foldAppE,
+    unfoldAppE, foldAppE, pat2Call,
hunk ./src/Terms/Class.hs 192
+    -- < Returns 'True' if the term 't' contains variables
+    hasVars         :: t -> Bool
+    hasVars = not.null.getVars
+    
hunk ./src/Terms/Class.hs 267
-            (P i)     -> maybe t id $  moveToSubtermE i t (Just.(substitute s Root))
-            (Dot p i) -> maybe t id $  moveToSubtermE i t (Just.(substitute s p))
+            (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))
hunk ./src/Terms/Class.hs 424
-moveToSubtermE :: (Monad m) => Int -> Exp -> (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 :: (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"
hunk ./src/Terms/Class.hs 429
-moveToSubtermE i t@(AppE _ _ ) f  = 
-   liftM foldAppE (applyAtIndex (unfoldAppE t) i f)
+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)
hunk ./src/Terms/Class.hs 434
-moveToSubtermE i (TupE es) f      = 
+moveToSubtermE (TupE es) i f      = 
hunk ./src/Terms/Class.hs 437
-moveToSubtermE i (ListE (e:es)) f = do
+moveToSubtermE (ListE (e:es)) i f = do
hunk ./src/Terms/Class.hs 440
-    return $ ListE (e:es)
+    return $ ListE (e':es')
hunk ./src/Terms/Class.hs 442
-moveToSubtermE 1 (InfixE (Just e1) op e2) f = 
+moveToSubtermE (InfixE (Just e1) op e2) 0 f = 
hunk ./src/Terms/Class.hs 444
-moveToSubtermE 2 (InfixE e1 op (Just e2)) f = 
+moveToSubtermE (InfixE e1 op (Just e2)) 1 f = 
hunk ./src/Terms/Class.hs 446
-moveToSubtermE _ (InfixE _ _ _ ) _          = 
-    fail "Terms.moveToSubtermE: No subterm at position"
+moveToSubtermE (InfixE _ op _ ) i _          = 
+    fail $ "Terms.moveToSubtermE: No subterm at position " ++ (show i) ++ 
+           " of operator " ++ (show op)
hunk ./src/Terms/Class.hs 451
-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
+--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
hunk ./src/Terms/Class.hs 483
-    return $  ListP (p:ps)
+    return $  ListP (p':ps')
hunk ./src/Terms/Class.hs 489
---compareAtRootP :: Pat -> Pat -> Bool
---compareAtRootP (VarP _)(VarP _)               = True
---compareAtRootP (LitP l1)(LitP l2)             = l1 == l2 
---compareAtRootP (ConP n1 _)(ConP n2 _ )        = n1 == n2
---compareAtRootP (InfixP _ p1 _)(InfixP _ p2 _) = p1 == p2 
---compareAtRootP (ListP []) (ListP [])                    = True
---compareAtRootP (ListP []) (ListP _)                     = False
---compareAtRootP (ListP _)  (ListP [])                    = False
---compareAtRootP (ListP _)  (ListP _)                     = True
---compareAtRootP (TupP p1s)(TupP p2s)           = (length p1s) == (length p2s)
---compareAtRootP  _ _                           = False
+pat2Call :: Name ->[Pat] -> Exp
+pat2Call n ps = foldAppE $ (ConE n):(map pat2Exp ps)    
+    
+pat2Exp :: Pat -> Exp
+pat2Exp (VarP i) = (VarE i)
+pat2Exp (LitP l) = (LitE l) 
+pat2Exp (ConP n ps) = foldAppE $ (ConE n):(map pat2Exp ps)
+pat2Exp (InfixP l n r) = flip InfixE (ConE n) (Just . pat2Exp $ l)(Just . pat2Exp $ r) 
+pat2Exp (ListP l) = ListE $ map pat2Exp l
+pat2Exp (TupP ps) = ListE $ map pat2Exp ps
+pat2Exp p = error $ "Terms.class.pat2Exp: Pattern " ++ show p ++
+                  " cannot be transformed into an Expression!"