The Monad and MonadFix instances for Either (formerly in the mtl
package) are moved to Control.Monad.Instances and Control.Monad.Fix
respectively. The Monad instance is still an orphan, to retain Haskell
98 compatibility, but the MonadFix instance is together with its class.
The Error constraint is removed from both instances, and the default
definition of fail is used.
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
instance Functor (Either a) where
fmap _ (Left x) = Left x
fmap f (Right y) = Right (f y)
+
+instance Monad (Either e) where
+ return = Right
+ Left l >>= _ = Left l
+ Right r >>= k = k r