Ticket #114: ControlMonadMatchInstances.hs

File ControlMonadMatchInstances.hs, 465 bytes (added by claus, 7 years ago)

instances of standard types/classes, factored out of main support library

Line 
1{-# OPTIONS_GHC -fglasgow-exts #-}
2
3-- factor out instances of standard classes for
4-- standard types, to allow conflict avoidance
5
6module ControlMonadMatchInstances where
7
8import Control.Monad
9
10instance Monad (Either String) where
11  fail   = Left
12  return = Right
13  (Left a)  >>= b = Left a
14  (Right a) >>= b = b a
15
16instance MonadPlus (Either String) where
17  mzero = Left "mzero"
18  (Left _)      `mplus` b = b
19  (a@(Right _)) `mplus` _ = a