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