Remove MonadFail (ST s) instance

Oleg Grenrus oleg.grenrus at iki.fi
Mon Nov 25 12:13:55 UTC 2019


As replied by Henning, fail @IO = throwIO . userError,
which isn't throwing a pure exception. The IO instance is in the spirit 
of MonadFail proposal, it behaves well.

If you write GHC-7.10..GHC-8.x code, you **should** depend on `fail` 
package, to get MonadFail class for GHC-7.x.
See 
https://prime.haskell.org/wiki/Libraries/Proposals/MonadFail#Adaptingoldcode

On 25.11.2019 12.28, Bertram Felgenhauer via Libraries wrote:
> Oleg Grenrus wrote:
>> I cannot see any justification for that instance
>>
>>      -- | @since 4.11.0.0
>>      instance Fail.MonadFail (ST s) where
>>          fail s = errorWithoutStackTrace s
> It's certainly not in the spirit of the MonadFail proposal. Arguably,
> *all* implementations of `fail` in terms of `error*` are wrong, even
> the one for IO. (I suspect dropping the instance for IO would cause a
> lot of pain though...)
>
> I'm neutral on the proposal itself.
>
>> If someone wants to fail pattern matches in `ST s`, please do that
>> explicitly.
> However, I don't like this framing. In practice, there's at least one
> other use of MonadFail for historical reasons: generic code that may
> fail. Before MFP, one could write (and people have written) code like
>
>      fooM :: Monad m => a -> m b
>      fooM ... = fail "unsupported case"
>
> It is easy enough to change the signature of such a `fooM` to require
> MonadFail, but then the function becomes impossible to use for monads
> that don't have a MonadFail instance. So after the MFP, one should
> provide two functions instead, one using `error` and another one
> using `fail`...
>
>> Note: compatibility package
>> https://hackage.haskell.org/package/fail-4.9.0.0/docs/Control-Monad-Fail.html
>> doesn't have that instance, so I suspect not-that many use(d) that instance.
> Or perhaps nobody cares about ghc-7.10 anymore.
>
> Cheers,
>
> Bertram
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


More information about the Libraries mailing list