+{-# LANGUAGE CPP #-}
+
-----------------------------------------------------------------------------
-- |
-- Module : Control.Monad.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.
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
+