[Haskell-cafe] MTL vs Free-monads, what are your experiences

William Yager will.yager at gmail.com
Wed Oct 19 22:03:27 UTC 2016


On Wed, Oct 19, 2016 at 3:19 PM, Christopher Allen <cma at bitemyapp.com>
wrote:

>
> Here catch is:
>
> catch :: (Exception e, MonadCatch m) => m a -> (e -> m a) -> m a
>
>
In my mind, this is inferior to the Purescript example, because you have
not discharged the MonadCatch instance. That is to say, the result monad
continues to have a MonadCatch instance, even though we may want to
explicitly express that we have *already* caught any exceptions, so the
result type need not be a MonadCatch.

In the Purescript example, the result monad no longer has the EXCEPTION
effect, so you have demonstrated statically that the exception has already
been caught! This is very useful. You can't express this in the style
you're advocating  (which, to be clear, is the style I use most of the
time).

In other words, the purescript approach has the benefits of both explicitly
enumerating the entire monad transformer stack (you can statically
determine exactly which effects are possible *and* which are not, and you
can discharge individual layers of the stack) and of using typeclass
constraints (you aren't typing out redundant information and you don't have
to specify where in the monad transformer stack the effect is handled).
It's the best of both worlds.


>
> >Another advantage is that the Purescipt example uses a concrete type
>
> I'm not sure I understand. What are you saying is concrete here?


I should have been more clear; the type is polymorphic, but does not have
any constraints outside of the type. This isn't a formal advantage so much
as a psychological/syntactic advantage. As I said, it's inconvenient to
have to mentally sub in constraints on the LHS of the "=>" into the type
variables on the RHS of the "=>". The Purescript approach is easier to read
for me, even though I've been using the typeclass approach for years.


Like I said, I haven't actually used Purescript, so I'm sure there are
additional use cases I'm missing. But this is what stands out.

Cheers,
Will
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20161019/2ac70ecc/attachment.html>


More information about the Haskell-Cafe mailing list