[generic cata applies to any argument
martin.hofmann@uni-bamberg.de**20091216150845] hunk ./src/Igor2/Data/IgorMonad.hs 236
+-- may fail
+ctorsOf :: Name -> IM [Name]
+ctorsOf n = (lift . lift . lift . lift . getCtors $ n) >>=
+             maybe (fail $ "No ctors for " ++ (show n)) return 
hunk ./src/Igor2/Data/IgorMonad.hs 241
-ctorsOf :: Name -> IM (Maybe [Name])
-ctorsOf = lift . lift . lift . lift . getCtors
hunk ./src/Igor2/RuleDevelopment/Cata.hs 23
+
hunk ./src/Igor2/RuleDevelopment/Cata.hs 26
+    
hunk ./src/Igor2/RuleDevelopment/Cata.hs 28
-      else do i <- (applyC $ detCataArg . lhs .crul $ cr) :: (IM (Either String Int))
-              either (const $ noCata "Wrong Type") (genericCata cr) i
---     else do b <- (applyC $ matches (lastArg cr)  muVar) :: (IM (Either String Bool))
---             if either (const False) id b then genericCata cr
---              else noCata "Wrong Type"
+      else do is <- cataArgIs . lhs . crul $ cr
+              rs <- mapM (genericCata cr) is
+              return $ case concat rs of [] -> []; (x:_) -> [x] -- only the first possibility
+--              return . concat $ rs -- do all possibilities
hunk ./src/Igor2/RuleDevelopment/Cata.hs 33
--- get the index of the last argument whose type is instance of Mu 
-detCataArg :: (MonadError e m) => [TExp] -> C m Int
-detCataArg as = doit $ zip as [0..]
+-- get the indices of all arguments In reverse order) which are catamorhpism enabled 
+cataArgIs :: [TExp] -> IM [Int]
+cataArgIs as = mapM doit (zip as [0..]) >>= return . reverse . rights
hunk ./src/Igor2/RuleDevelopment/Cata.hs 37
-    doit []     = fail "No appropriate type!"
-    doit (x:xs) = doit xs `catchError` \_ ->
-                    matches (fst x) muVar >> return (snd x)
+    doit :: (TExp,Int) -> IM (Either String Int)
+    doit x = applyC $ (matches (fst x) muVar) >> return (snd x)
hunk ./src/Igor2/RuleDevelopment/Cata.hs 45
+    llogNO $ text "Check argument" <+> int i <+> text "for general 'cata'!"
hunk ./src/Igor2/RuleDevelopment/Cata.hs 47
-    ctors <- maybe (return Nothing) ctorsOf $ dataName . typeOf . (ithArg i) $ cr
-    (maybe (fail $ "No Partition possible for argument " ++ (show i) ++ "! ") return 
-        (ctors >>= partByCtors i evi) >>= mkCata i cr) 
-        `catchError`
-         \e -> noCata $ "Universal Property not satisfied for argument " ++ 
-                        (show i) ++ "! " ++ e
+    (dataTypeName i cr >>= ctorsOf >>= partByCtors i evi >>= mkCata i cr) 
+     `catchError` \e -> noCata i e 
+    where
+    -- data type Name of the th argument of the covering rule
+    dataTypeName = ((dataName . typeOf) .) . ithArg 
hunk ./src/Igor2/RuleDevelopment/Cata.hs 53
-partByCtors :: Int -> [CovrRule] -> [Name] -> Maybe [[CovrRule]]
+partByCtors :: (Monad m) => Int -> [CovrRule] -> [Name] -> m [[CovrRule]]
hunk ./src/Igor2/RuleDevelopment/Cata.hs 57
-                  if null rs' then Nothing else Just rs'
+                  if null rs' then noPartition  else return rs'
hunk ./src/Igor2/RuleDevelopment/Cata.hs 62
-    hasCtor n  _                 = False 
+    hasCtor n  _                 = False  
+    noPartition = fail $ "No Partition possible for argument " ++ (show i) ++ "! "
hunk ./src/Igor2/RuleDevelopment/Cata.hs 124
-noCata s = llogNO (text "Catamorphism not applicable: " <+> text s) >> return []
+noCata i e = llogNO (text "Catamorphism not applicable:" <+> 
+                     text "Universal Property not satisfied for argument" <+>
+                     int i <+> text "!" <+> text (show e)) >> 
+             return [] 