[change ContextMonad to use a type alias, remove dependence on 'Either' monad instance
John Meacham <john@repetae.net>**20120130063357
 Ignore-this: 5ae3b1bab9cd933f2e494d802b154859
] hunk ./src/E/Lint.hs 31
+import Util.ContextMonad
hunk ./src/E/Lint.hs 91
-lintCheckE onerr dataTable tvr e | flint = case inferType dataTable [] e of
+lintCheckE onerr dataTable tvr e | flint = case runContextEither $ inferType dataTable [] e of
hunk ./src/E/Main.hs 455
+    wdump FD.CorePass $ dumpCore "before-TypeAnalyze-Main-AfterSimp" prog
hunk ./src/E/Program.hs 20
+import Util.ContextMonad
hunk ./src/E/Program.hs 130
-    let (ty,pty) = case inferType dataTable [] e of
+    let (ty,pty) = case runContextEither (inferType dataTable [] e) of
hunk ./src/E/TypeCheck.hs 246
-inferType :: ContextMonad String m => DataTable -> [(TVr,E)] -> E -> m E
+inferType :: (ContextMonad m, ContextOf m ~ String) => DataTable -> [(TVr,E)] -> E -> m E
hunk ./src/E/TypeCheck.hs 370
-            Right () -> return (e1)
-            Left s -> failDoc $ text "eq:" <+> align $ vcat [ text s, prettyE (e1), prettyE (e2) ]
+            Just () -> return (e1)
+            Nothing -> failDoc $ text "eq:" <+> align $ vcat [ prettyE (e1), prettyE (e2) ]
hunk ./src/E/TypeCheck.hs 389
-    typecheck dataTable e = case typeInfer'' dataTable [] e of
+    typecheck dataTable e = case runContextEither $ typeInfer'' dataTable [] e of
hunk ./src/E/TypeCheck.hs 411
-typeInfer dataTable e = case typeInfer'' dataTable [] e of
+typeInfer dataTable e = case runContextEither $ typeInfer'' dataTable [] e of
hunk ./src/E/TypeCheck.hs 416
-typeInfer' dataTable ds e = case typeInfer'' dataTable ds e of
+typeInfer' dataTable ds e = case runContextEither $ typeInfer'' dataTable ds e of
hunk ./src/E/TypeCheck.hs 430
-instance ContextMonad String Tc where
+instance ContextMonad Tc where
+    type ContextOf Tc = String
hunk ./src/E/TypeCheck.hs 469
-typeInfer'' :: ContextMonad String m => DataTable -> [(TVr,E)] -> E -> m E
+typeInfer'' :: (ContextMonad m, ContextOf m ~ String) => DataTable -> [(TVr,E)] -> E -> m E
hunk ./src/FrontEnd/KindInfer.hs 129
-instance ContextMonad String Ki where
+instance ContextMonad Ki where
+    type ContextOf Ki = String
hunk ./src/Util/ContextMonad.hs 5
-
-class Monad m => ContextMonad c m | m -> c where
-    withContext :: c -> m a -> m a
-
+class Monad m => ContextMonad m where
+    type ContextOf m
+    withContext :: ContextOf m -> m a -> m a
hunk ./src/Util/ContextMonad.hs 13
-
-instance ContextMonad String (Either [String]) where
-    withContext s (Right x) = Right x
-    withContext s (Left cs) = Left  (s:cs)
+newtype ContextEither a = ContextEither (Either [String] a)
+    deriving(Functor)
hunk ./src/Util/ContextMonad.hs 16
+runContextEither (ContextEither a) = a
hunk ./src/Util/ContextMonad.hs 18
-runSimpleContextMonad :: Either [String] a -> a
-runSimpleContextMonad (Left ss) = error $ unlines ss
-runSimpleContextMonad (Right x) = x
+instance Monad ContextEither where
+    fail s = ContextEither (Left [s])
+    ContextEither x >>= y = case x of
+        Left ss -> ContextEither (Left ss)
+        Right v -> y v
+    return x = ContextEither (Right x)
hunk ./src/Util/ContextMonad.hs 25
+instance ContextMonad ContextEither where
+    type ContextOf ContextEither = String
+    withContext s (ContextEither (Left ss)) = ContextEither (Left (s:ss))
+    withContext _ r = r
hunk ./src/Util/ContextMonad.hs 30
+runSimpleContextMonad :: ContextEither a -> a
+runSimpleContextMonad (ContextEither (Left ss)) = error $ unlines ss
+runSimpleContextMonad (ContextEither (Right x)) = x