From 87d1ac62b8114727d8756a4c239992bff6c854ea Mon Sep 17 00:00:00 2001 From: Bas van Dijk Date: Sun, 16 May 2010 17:17:56 +0000 Subject: [PATCH] Added Applicative and Alternative instances for STM --- Control/Applicative.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Control/Applicative.hs b/Control/Applicative.hs index e60182d..a2755eb 100644 --- a/Control/Applicative.hs +++ b/Control/Applicative.hs @@ -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) -- 1.7.10.4