Update base for latest Safe Haskell.
[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 -- |
8 -- Module : Control.Monad.Instances
9 -- Copyright : (c) The University of Glasgow 2001
10 -- License : BSD-style (see the file libraries/base/LICENSE)
11 --
12 -- Maintainer : libraries@haskell.org
13 -- Stability : provisional
14 -- Portability : portable
15 --
16 -- 'Functor' and 'Monad' instances for @(->) r@ and
17 -- 'Functor' instances for @(,) a@ and @'Either' a@.
18
19 module Control.Monad.Instances (Functor(..),Monad(..)) where
20
21 import Prelude
22
23 instance Functor ((->) r) where
24 fmap = (.)
25
26 instance Monad ((->) r) where
27 return = const
28 f >>= k = \ r -> k (f r) r
29
30 instance Functor ((,) a) where
31 fmap f (x,y) = (x, f y)
32
33 instance Functor (Either a) where
34 fmap _ (Left x) = Left x
35 fmap f (Right y) = Right (f y)
36
37 instance Monad (Either e) where
38 return = Right
39 Left l >>= _ = Left l
40 Right r >>= k = k r
41