ErrorT is deprecated, but ExceptT doesn't fit

爱⌒轻易说出口 提交于 2020-01-03 11:33:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!