@@ -0,0 +1,44 @@
1+{-# LANGUAGE DeriveDataTypeable #-}
2+{-# LANGUAGE DeriveFunctor #-}
4+module Database.PostgreSQL.Simple.Ok where
6+import Control.Applicative
7+import Control.Exception
10+-- FIXME: [SomeException] should probably be a difference list
12+data Ok a = Errors [SomeException] | Ok !a
13+ deriving(Show, Typeable, Functor)
15+instance Eq a => Eq (Ok a) where
16+ Errors _ == Errors _ = True
17+ Ok a == Ok b = a == b
20+instance Applicative Ok where
23+ Errors es <*> _ = Errors es
24+ _ <*> Errors es = Errors es
25+ Ok f <*> Ok a = Ok (f a)
27+instance Alternative Ok where
31+ Errors _ <|> b@(Ok _) = b
32+ Errors as <|> Errors bs = Errors (as ++ bs)
34+instance Monad Ok where
37+ Errors es >>= _ = Errors es
39+ -- TODO: add a definition for "fail", akin to
41+ -- fail str = Errors [SomeException (error str)]
43+ -- but *correct*, as this will throw an exception if you try to
44+ -- examine the exception.