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