X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Control%2FMonad%2FFix.hs;h=a1309faccd41db6574dc8bd5f36297708d635b35;hb=41839f14458d79ac02ad11087885c7f4f1144a73;hp=d0582200ed459df42c0c961196909c473b478701;hpb=c7d2a7507a72b02be171fd1087a2105d66defb6a;p=ghc-base.git diff --git a/Control/Monad/Fix.hs b/Control/Monad/Fix.hs index d058220..a1309fa 100644 --- a/Control/Monad/Fix.hs +++ b/Control/Monad/Fix.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE CPP #-} + ----------------------------------------------------------------------------- -- | -- Module : Control.Monad.Fix @@ -29,6 +31,9 @@ import Data.Function (fix) #ifdef __HUGS__ import Hugs.Prelude (MonadFix(mfix)) #endif +#if defined(__GLASGOW_HASKELL__) +import GHC.ST +#endif #ifndef __HUGS__ -- | Monads having fixed points with a \'knot-tying\' semantics. @@ -63,6 +68,7 @@ class (Monad m) => MonadFix m where instance MonadFix Maybe where mfix f = let a = f (unJust a) in a where unJust (Just x) = x + unJust Nothing = error "mfix Maybe: Nothing" -- List: instance MonadFix [] where @@ -74,5 +80,18 @@ instance MonadFix [] where instance MonadFix IO where mfix = fixIO +-- Prelude types with Monad instances in Control.Monad.Instances + instance MonadFix ((->) r) where mfix f = \ r -> let a = f a r in a + +instance MonadFix (Either e) where + mfix f = let a = f (unRight a) in a + where unRight (Right x) = x + unRight (Left _) = error "mfix Either: Left" + +#if defined(__GLASGOW_HASKELL__) +instance MonadFix (ST s) where + mfix = fixST +#endif +