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