Commit 6583bc7b authored by Ross Paterson's avatar Ross Paterson
Browse files

move Monad and MonadFix instances for Either from mtl (proposal #4159)

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.
parent 4c45d8f7
......@@ -78,9 +78,16 @@ 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
......@@ -31,3 +31,8 @@ instance Functor ((,) a) where
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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment