问题
I had a monadic computation. At some point it started requiring a MonadFail constraint because of a monadic pattern-match.
My easy fix was to run it with this:
fmap (either error id) . runErrorT
Yet ouch:
Deprecated: "Use Control.Monad.Trans.Except instead"
So it appears that ErrorT
is deprecated, and I'm to use ExceptT
instead. That sounds fine from the outside, but it doesn't appear like ExceptT is a drop-in replacement at all! Just look at the instance declarations:
instance (Monad m, Error e) => MonadFail (ErrorT e m)
instance MonadFail m => MonadFail (ExceptT e m)
ErrorT
provides a MonadFail implementation. ExceptT
merely lifts it.
I'm not quite sure where to go from this point.
my code eventually won't have the refutable bind at all. It's one of those cases where it's statically known to work, yet not proven to the type checker yet. I'll get there, but it'll take a while. (Like, I'm going to need dependent types, so I'm going to need to learn dependent types. It'll take a while.)
yet in the meantime, my code needs to bind, and really I'm fine with
error
being called if I mess up.
It seems what I'm looking for is some generic MonadFail
implementation that allows me to… well, do what I want with a pattern failing to match. ErrorT
did this, and ExceptT
doesn't.
What are my non-deprecated options?
来源:https://stackoverflow.com/questions/59537969/errort-is-deprecated-but-exceptt-doesnt-fit