add ga_inl, ga_inr
[ghc-base.git] / Control / Monad / Instances.hs
1 {-# OPTIONS_NHC98 --prelude #-}
2 -- This module deliberately declares orphan instances:
3 {-# OPTIONS_GHC -fno-warn-orphans #-}
4 -----------------------------------------------------------------------------
5 -- |
6 -- Module      :  Control.Monad.Instances
7 -- Copyright   :  (c) The University of Glasgow 2001
8 -- License     :  BSD-style (see the file libraries/base/LICENSE)
9 --
10 -- Maintainer  :  libraries@haskell.org
11 -- Stability   :  provisional
12 -- Portability :  portable
13 --
14 -- 'Functor' and 'Monad' instances for @(->) r@ and
15 -- 'Functor' instances for @(,) a@ and @'Either' a@.
16
17 module Control.Monad.Instances (Functor(..),Monad(..)) where
18
19 import Prelude
20
21 instance Functor ((->) r) where
22         fmap = (.)
23
24 instance Monad ((->) r) where
25         return = const
26         f >>= k = \ r -> k (f r) r
27
28 instance Functor ((,) a) where
29         fmap f (x,y) = (x, f y)
30
31 instance Functor (Either a) where
32         fmap _ (Left x) = Left x
33         fmap f (Right y) = Right (f y)
34
35 instance Monad (Either e) where
36         return = Right
37         Left  l >>= _ = Left l
38         Right r >>= k = k r