doc tweak for Directory file type: file names are '\0'-separated
[ghc-base.git] / Control / Applicative.hs
index 8aa86e1..154b591 100644 (file)
@@ -36,7 +36,6 @@ module Control.Applicative (
         ) where
 
 import Prelude hiding (id,(.))
-import qualified Prelude (id)
 
 import Control.Category
 import Control.Arrow
@@ -46,6 +45,10 @@ import Control.Monad.Instances ()
 import Data.Functor ((<$>), (<$))
 import Data.Monoid (Monoid(..))
 
+#ifdef __GLASGOW_HASKELL__
+import GHC.Conc (STM, retry, orElse)
+#endif
+
 infixl 3 <|>
 infixl 4 <*>, <*, *>, <**>
 
@@ -146,6 +149,16 @@ instance Applicative IO where
         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)
@@ -154,6 +167,11 @@ instance Monoid a => Applicative ((,) a) where
         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 }