Ticket #5685: 0001-Moved-the-instances-from-Control.Monad.Instances-to-.patch

File 0001-Moved-the-instances-from-Control.Monad.Instances-to-.patch, 4.0 KB (added by basvandijk, 2 years ago)
  • Control/Applicative.hs

    From 06de386f9fbd808855f922dd0dc1362edc303db6 Mon Sep 17 00:00:00 2001
    From: Bas van Dijk <v.dijk.bas@gmail.com>
    Date: Wed, 7 Dec 2011 15:37:31 +0100
    Subject: [PATCH] Moved the instances from Control.Monad.Instances to GHC.Base
     and Data.Either
    
    ---
     Control/Applicative.hs     |    1 -
     Control/Monad/Fix.hs       |    6 ------
     Control/Monad/Instances.hs |   22 ++--------------------
     Data/Either.hs             |    9 +++++++++
     GHC/Base.lhs               |   10 ++++++++++
     5 files changed, 21 insertions(+), 27 deletions(-)
    
    diff --git a/Control/Applicative.hs b/Control/Applicative.hs
    index 248bbac..bf58bea 100644
    a b import Prelude hiding (id,(.)) 
    5050import Control.Category 
    5151import Control.Arrow (Arrow(arr, (&&&)), ArrowZero(zeroArrow), ArrowPlus((<+>))) 
    5252import Control.Monad (liftM, ap, MonadPlus(..)) 
    53 import Control.Monad.Instances () 
    5453#ifndef __NHC__ 
    5554import Control.Monad.ST.Safe (ST) 
    5655import qualified Control.Monad.ST.Lazy.Safe as Lazy (ST) 
  • Control/Monad/Fix.hs

    diff --git a/Control/Monad/Fix.hs b/Control/Monad/Fix.hs
    index b1fe43d..a3d2c89 100644
    a b module Control.Monad.Fix ( 
    2727 
    2828import Prelude 
    2929import System.IO 
    30 import Control.Monad.Instances () 
    3130import Data.Function (fix) 
    3231#ifdef __HUGS__ 
    3332import Hugs.Prelude (MonadFix(mfix)) 
    class (Monad m) => MonadFix m where 
    6564 
    6665-- Instances of MonadFix for Prelude monads 
    6766 
    68 -- Maybe: 
    6967instance MonadFix Maybe where 
    7068    mfix f = let a = f (unJust a) in a 
    7169             where unJust (Just x) = x 
    7270                   unJust Nothing  = error "mfix Maybe: Nothing" 
    7371 
    74 -- List: 
    7572instance MonadFix [] where 
    7673    mfix f = case fix (f . head) of 
    7774               []    -> [] 
    7875               (x:_) -> x : mfix (tail . f) 
    7976 
    80 -- IO: 
    8177instance MonadFix IO where 
    8278    mfix = fixIO  
    8379 
    84 -- Prelude types with Monad instances in Control.Monad.Instances 
    85  
    8680instance MonadFix ((->) r) where 
    8781    mfix f = \ r -> let a = f a r in a 
    8882 
  • Control/Monad/Instances.hs

    diff --git a/Control/Monad/Instances.hs b/Control/Monad/Instances.hs
    index 3849e3b..f30f7a4 100644
    a b  
    1313-- Stability   :  provisional 
    1414-- Portability :  portable 
    1515-- 
     16-- /This module is DEPRECATED and will be removed in the future!/ 
     17-- 
    1618-- 'Functor' and 'Monad' instances for @(->) r@ and 
    1719-- 'Functor' instances for @(,) a@ and @'Either' a@. 
    1820 
    1921module Control.Monad.Instances (Functor(..),Monad(..)) where 
    2022 
    2123import 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  
  • Data/Either.hs

    diff --git a/Data/Either.hs b/Data/Either.hs
    index cdfa761..46d5c40 100644
    a b hold a correct value (mnemonic: \"right\" also means \"correct\"). 
    5656data  Either a b  =  Left a | Right b 
    5757  deriving (Eq, Ord, Read, Show, Generic) 
    5858 
     59instance Functor (Either a) where 
     60    fmap _ (Left x) = Left x 
     61    fmap f (Right y) = Right (f y) 
     62 
     63instance Monad (Either e) where 
     64    return = Right 
     65    Left  l >>= _ = Left l 
     66    Right r >>= k = k r 
     67 
    5968-- | Case analysis for the 'Either' type. 
    6069-- If the value is @'Left' a@, apply the first function to @a@; 
    6170-- if it is @'Right' b@, apply the second function to @b@. 
  • GHC/Base.lhs

    diff --git a/GHC/Base.lhs b/GHC/Base.lhs
    index e062a36..4b10767 100644
    a b class Monad m where 
    229229    {-# INLINE (>>) #-} 
    230230    m >> k      = m >>= \_ -> k 
    231231    fail s      = error s 
     232 
     233instance Functor ((->) r) where 
     234    fmap = (.) 
     235 
     236instance Monad ((->) r) where 
     237    return = const 
     238    f >>= k = \ r -> k (f r) r 
     239 
     240instance Functor ((,) a) where 
     241    fmap f (x,y) = (x, f y) 
    232242\end{code} 
    233243 
    234244