[remove lots of MonadError constraints
Helmut Grohne <grohne@cs.uni-bonn.de>**20150123124916
 Ignore-this: 51e4f8ff1088b22454cc098cac37251
 
 Some uses of catchError result in a computation that definitely no longer
 transports an error. Still such uses were constrained by MonadError. By
 introducing a safeCatchErrorC function, we can escape from the MonadError into
 a weaker monad and elide these constraints in many places. Since
 safeCatchErrorC forces the MonadError on its first parameter to Either String,
 some of these computations practically change their monad. For instance,
 normalPat was living in the IO monad. Therefore, this change might induce
 semantic changes (for instance due to the use of fail in other places).
] hunk ./src/Igor2/Data/HypoSpace.hs 45
-initHSpace :: (MonadPlus m, Error e, MonadError e m) => CovrRule -> C m HSpace
-initHSpace r = hypo [r] >>= return . pushHypo emptyHSpace
+initHSpace :: (MonadPlus m) => CovrRule -> C m HSpace
+initHSpace r = liftM (pushHypo emptyHSpace) $ hypo [r]
hunk ./src/Igor2/Data/Hypotheses.hs 69
-hypo :: (MonadPlus m, Error e, MonadError e m) => [CovrRule] -> C m Hypo
+hypo :: (MonadPlus m) => [CovrRule] -> C m Hypo
hunk ./src/Igor2/Data/Hypotheses.hs 97
-simplifiedBindings :: (MonadPlus m, Error e, MonadError e m) =>
+simplifiedBindings :: (MonadPlus m) =>
hunk ./src/Igor2/Data/Hypotheses.hs 176
-updateRating :: (MonadPlus m, Error e, MonadError e m) => Hypo -> C m Hypo
+updateRating :: (MonadPlus m) => Hypo -> C m Hypo
hunk ./src/Igor2/Data/Hypotheses.hs 232
-numberOfPartitions ::  (Error e, MonadError e m) => Hypo -> C m Int
+numberOfPartitions ::  Monad m => Hypo -> C m Int
hunk ./src/Igor2/Data/Hypotheses.hs 235
-numberOfClosedPartitions :: (Error e, MonadError e m) => Hypo -> C m Int
+numberOfClosedPartitions :: Monad m => Hypo -> C m Int
hunk ./src/Igor2/Data/Hypotheses.hs 239
-numberOfLeastPatterns :: (Error e, MonadError e m) => Rules -> C m Int
+numberOfLeastPatterns :: Monad m => Rules -> C m Int
hunk ./src/Igor2/Data/Hypotheses.hs 253
-heuristic :: (MonadPlus m, Error e, MonadError e m) => Hypo -> C m ([Float], Float)
+heuristic :: (MonadPlus m) => Hypo -> C m ([Float], Float)
hunk ./src/Igor2/Data/Rateable.hs 56
-    rate :: (MonadPlus m, Error e, MonadError e m) => r -> C m RatingData
+    rate :: (MonadPlus m) => r -> C m RatingData
hunk ./src/Igor2/Data/Rules.hs 227
-matchLhss :: (Error e, MonadError e m) => Rule -> Rule -> C m Bool
+matchLhss :: Monad m => Rule -> Rule -> C m Bool
hunk ./src/Igor2/Data/Rules.hs 230
-matchRhs :: (Error e, MonadError e m) => Rule -> Rule -> C m Bool
+matchRhs :: Monad m => Rule -> Rule -> C m Bool
hunk ./src/Igor2/Data/Rules.hs 316
-replaceInAll :: (MonadPlus m, Error e, MonadError e m) => TExp -> TExp -> [(Name,Rules)] -> C m [(Name,Rules)]
+replaceInAll :: (MonadPlus m) => TExp -> TExp -> [(Name, Rules)] -> C m [(Name, Rules)]
hunk ./src/Igor2/Data/Rules.hs 324
-replaceCall :: (MonadPlus m, Error e, MonadError e m) => Rule -> RHS -> C m RHS
-replaceCall r rs = replaceCall' r rs
+replaceCall :: (MonadPlus m) => Rule -> RHS -> C m RHS
+replaceCall _ t@(TVarE _ _)       = return t
+replaceCall _ t@(TLitE _ _)       = return t
+replaceCall _ t@(TWildE _ _)      = return t
+replaceCall _ t@(TConE n _)       = return t
+replaceCall r t = matchEval [t] r `safeCatchErrorC` \_ -> repSubterms t
hunk ./src/Igor2/Data/Rules.hs 331
-    replaceCall' _ t@(TVarE _ _)       = return t
-    replaceCall' _ t@(TLitE _ _)       = return t
-    replaceCall' _ t@(TWildE _ _)      = return t
-    replaceCall' _ t@(TConE n _)       = return t
-    replaceCall' r t =  (matchEval [t] r) `catchError` \_ -> repSubterms t
-    repSubterms t = liftM (root t) $ mapM (replaceCall' r) (subterms t)
+    repSubterms :: MonadPlus m => RHS -> C m RHS
+    repSubterms t = liftM (root t) $ mapM (replaceCall r) (subterms t)
hunk ./src/Igor2/RuleDevelopment/Matching.hs 132
-     mkNormalPats io   = lift . fmap catMaybes . mapM (on normalPat crul io)
+     mkNormalPats io   = lift . fmap catMaybes . mapM (on ((lift .) . normalPat) crul io)
hunk ./src/Igor2/RuleDevelopment/Matching.hs 159
-normalPat :: Rule -> Rule -> LM (Maybe [TExp])
-normalPat cll tgt = lift $
-    (matchesRhs cll tgt >>=  return . (flip applyL (lhs tgt)) >>= return.Just)
-      `catchError` \_ -> return Nothing
+normalPat :: Monad m => Rule -> Rule -> C m (Maybe [TExp])
+normalPat cll tgt =
+    liftM (Just . flip applyL (lhs tgt)) (matchesRhs cll tgt)
+      `safeCatchErrorC` \_ -> return Nothing
hunk ./src/Syntax/Class/Unifier.hs 45
-    matches :: (Error e, MonadError e m) => t -> t -> C m Bool
-    matches t1 t2 = (match t1 t2 >>= return . const True)
-                      `catchError` \_ -> return False
+    matches :: Monad m => t -> t -> C m Bool
+    matches t1 t2 = liftM (const True) (match t1 t2) `safeCatchErrorC` const (return False)
hunk ./src/Syntax/Class/Unifier.hs 50
-    
-    matchesL :: (Error e, MonadError e m) => [t] -> [t] -> C m Bool
-    matchesL t1 t2 = (matchL t1 t2 >>= return . const True)
-                      `catchError` \_ -> return False 
+    matchesL :: Monad m => [t] -> [t] -> C m Bool
+    matchesL t1 t2 = liftM (const True) (matchL t1 t2) `safeCatchErrorC` const (return False)
hunk ./src/Syntax/Context.hs 11
+    safeCatchErrorC,
hunk ./src/Syntax/Context.hs 193
+
+safeCatchErrorC :: Monad m => C (Either String) a -> (String -> C m a) -> C m a
+safeCatchErrorC c h = mapReaderT return c >>= either h return
hunk ./src/Syntax/UnifyTy.hs 118
-simplify :: (Error e, MonadError e m) => TyCxt -> C m TyCxt
+simplify :: Monad m => TyCxt -> C m TyCxt
hunk ./src/Syntax/UnifyTy.hs 144
-entails :: (Error e, MonadError e m) => TyCxt -> Pred -> C m Bool
+entails :: Monad m => TyCxt -> Pred -> C m Bool
hunk ./src/Syntax/UnifyTy.hs 158
-byInst :: (Error e, MonadError e m) => Pred -> C m (Maybe [Pred])
+byInst :: Monad m => Pred -> C m (Maybe [Pred])
hunk ./src/Syntax/UnifyTy.hs 164
-tryInst :: (Error e, MonadError e m) => Pred -> Type -> C m (Maybe [Pred])
-tryInst t (ForallT _ c t') = do u <- match t t'; return $ Just (map (apply u) c)
-                              `catchError` \_ -> return Nothing
-tryInst t        t'        = do _ <- match t t'; return $ Just []
-                              `catchError` \_ -> return Nothing                          
-                               
- 
+tryInst :: Monad m => Pred -> Type -> C m (Maybe [Pred])
+tryInst t (ForallT _ c t') = liftM (\u -> Just (map (apply u) c)) (match t t')
+                             `safeCatchErrorC` (const (return Nothing))
+tryInst t        t'        = liftM (const (Just [])) (match t t')
+                             `safeCatchErrorC` (const (return Nothing))
+
hunk ./src/Syntax/UnifyTy.hs 200
-collectPreds :: (Error e, MonadError e m) => String -> [(Name,[Type])] -> Type -> C m [Pred]
-collectPreds vnm is (ForallT _ c (VarT _)) = mapM (\(AppT (ConT n) _) -> bySuper $ mkPred n vnm) c >>= return . concat 
-collectPreds vnm is (VarT _) = return . map ((flip mkPred vnm) . fst) $ is 
+collectPreds :: Monad m => String -> [(Name, [Type])] -> Type -> C m [Pred]
+collectPreds vnm is (ForallT _ c (VarT _)) = liftM concat $ mapM (\(AppT (ConT n) _) -> bySuper $ mkPred n vnm) c
+collectPreds vnm is (VarT _) = return . map (flip mkPred vnm . fst) $ is
