Added Applicative and Alternative instances for STM
authorBas van Dijk <v.dijk.bas@gmail.com>
Sun, 16 May 2010 17:17:56 +0000 (17:17 +0000)
committerBas van Dijk <v.dijk.bas@gmail.com>
Sun, 16 May 2010 17:17:56 +0000 (17:17 +0000)
Control/Applicative.hs

index e60182d..a2755eb 100644 (file)
@@ -45,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 <*>, <*, *>, <**>
 
@@ -145,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)