Skip to content

Commit

Permalink
remove MonadFail instances of ST
Browse files Browse the repository at this point in the history
CLC proposal: haskell/core-libraries-committee#33

The instances had `fail` implemented in terms of `error`, whereas the
idea of the `MonadFail` class is that the `fail` method should be
implemented in terms of the monad itself.
  • Loading branch information
ulysses4ever authored and Marge Bot committed Mar 4, 2022
1 parent 3570eda commit 65de2c6
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 18 deletions.
4 changes: 0 additions & 4 deletions libraries/base/Control/Monad/ST/Lazy/Imp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,6 @@ instance Monad (ST s) where
in
unST (k r) new_s

-- | @since 4.10
instance MonadFail (ST s) where
fail s = errorWithoutStackTrace s

-- | Return the value computed by an 'ST' computation.
-- The @forall@ ensures that the internal state used by the 'ST'
-- computation is inaccessible to the rest of the program.
Expand Down
5 changes: 0 additions & 5 deletions libraries/base/GHC/ST.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ module GHC.ST (

import GHC.Base
import GHC.Show
import Control.Monad.Fail

default ()

Expand Down Expand Up @@ -78,10 +77,6 @@ instance Monad (ST s) where
case (k r) of { ST k2 ->
(k2 new_s) }})

-- | @since 4.11.0.0
instance MonadFail (ST s) where
fail s = errorWithoutStackTrace s

-- | @since 4.11.0.0
instance Semigroup a => Semigroup (ST s a) where
(<>) = liftA2 (<>)
Expand Down
5 changes: 5 additions & 0 deletions libraries/base/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
CPtrdiff, CSize, CWchar, CSigAtomic, CLLong, CULLong, CBool, CIntPtr, CUIntPtr,
CIntMax, CUIntMax.

* Remove instances of `MonadFail` for the `ST` monad (lazy and strict) as per
the [Core Libraries proposal](/~https://github.com/haskell/core-libraries-committee/issues/33).
A [migration guide](/~https://github.com/haskell/core-libraries-committee/blob/main/guides/no-monadfail-st-inst.md)
is available.


## 4.16.0.0 *Nov 2021*

Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/ghci/scripts/T4175.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ type Maybe :: * -> *
data Maybe a = Nothing | Just a
-- Defined in ‘GHC.Maybe’
instance Traversable Maybe -- Defined in ‘Data.Traversable’
instance MonadFail Maybe -- Defined in ‘Control.Monad.Fail’
instance Foldable Maybe -- Defined in ‘Data.Foldable’
instance Applicative Maybe -- Defined in ‘GHC.Base’
instance Functor Maybe -- Defined in ‘GHC.Base’
instance MonadFail Maybe -- Defined in ‘Control.Monad.Fail’
instance Monad Maybe -- Defined in ‘GHC.Base’
instance Semigroup a => Monoid (Maybe a) -- Defined in ‘GHC.Base’
instance Semigroup a => Semigroup (Maybe a)
Expand Down
7 changes: 0 additions & 7 deletions testsuite/tests/monadfail/MonadFailErrors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ io = do



st :: ST s a
st = do
Just x <- undefined
undefined



reader :: r -> a
reader = do
Just x <- undefined
Expand Down
2 changes: 1 addition & 1 deletion testsuite/tests/monadfail/MonadFailErrors.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ MonadFailErrors.hs:28:5: error:
= do Just x <- undefined
undefined

MonadFailErrors.hs:49:5: error:
MonadFailErrors.hs:42:5: error:
• No instance for (MonadFail ((->) r))
arising from a do statement
with the failable pattern ‘Just x’
Expand Down

0 comments on commit 65de2c6

Please sign in to comment.