import Data.Functor ((<$>), (<$))
import Data.Monoid (Monoid(..))
+#ifdef __GLASGOW_HASKELL__
+import GHC.Conc (STM, retry, orElse)
+#endif
+
infixl 3 <|>
infixl 4 <*>, <*, *>, <**>
pure = return
(<*>) = ap
+#ifdef __GLASGOW_HASKELL__
+instance Applicative STM where
+ pure = return
+ (<*>) = ap
+
+instance Alternative STM where
+ empty = retry
+ (<|>) = orElse
+#endif
+
instance Applicative ((->) a) where
pure = const
(<*>) f g x = f x (g x)
pure x = (mempty, x)
(u, f) <*> (v, x) = (u `mappend` v, f x)
+instance Applicative (Either e) where
+ pure = Right
+ Left e <*> _ = Left e
+ Right f <*> r = fmap f r
+
-- new instances
newtype Const a b = Const { getConst :: a }