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

Christopher Allen cma at bitemyapp.com
Wed Oct 19 20:19:03 UTC 2016


With constraint kinds, you can make type synonyms that expand to
constraints, solving your syntactic objection, but I don't want to
discuss those further.


Far as error handling goes, I use MonadCatch/MonadError:
https://hackage.haskell.org/package/exceptions-0.8.3/docs/Control-Monad-Catch.html

Here catch is:

catch :: (Exception e, MonadCatch m) => m a -> (e -> m a) -> m a

Catch implies Throw, so.

This part,

>Another advantage is that the Purescipt example uses a concrete type

I'm not sure I understand. What are you saying is concrete here? You
still have a row of effects which could be any valid handler. I don't
think I understand the distinction you're making. Eff itself is
parameterized by the row of effects (# !) and the return type (*), so
there's nothing especially "concrete" about that to my mind as
contrasted with something instantiable as any Monad known to have a
Console API and a means of furnishing random values.

On Wed, Oct 19, 2016 at 1:41 PM, Will Yager <will.yager at gmail.com> wrote:
> It seems that there are several advantages to the Purescript approach.
>
> For example, this
>
> catchException
>   :: forall a e
>    . (Error -> Eff e a)
>   -> Eff (err :: EXCEPTION | e) a
>   -> Eff e a
>
>  would be unwieldy to express using typeclasses, requiring at least three
> constraints. I also find this style easier to read than constraints, as it
> requires no mental substitution. E.g. if I see
>
> (Foo m, Bar m, Bar n) => Baz -> <stuff ...> -> m a
>
> When I get to the end of the type, I have to go back to the beginning to
> figure out what m is. I can't read left-to-right. This happens a lot with
> constraint-based monad composition.
>
> Another advantage is that the Purescipt example uses a concrete type, which
> is often easier to reason about than "ad-hoc" typeclass abstractions like
> MonadRandom. However, it looks like you still get the flexibility of ad-hoc
> typeclasses, because you get to pick any function that discharges the effect
> type in the given effect monad.
>
> Like I said, I have not used it, but these are what I've noticed from
> topical observation.
>
> Apologies for the formatting; copying that code example appears to have
> confused the iOS mail app.
>
> Cheers,
>
> Will
>
>
>
> On Oct 19, 2016, at 12:26, Christopher Allen <cma at bitemyapp.com> wrote:
>
> It's not really more direct. It's an unordered collection of effects
> you can use. IME it's a less efficient mtl-style, but YMMV.
>
> Taking an example from a PureScript tutorial:
>
> func :: Eff (console :: CONSOLE, random :: RANDOM) Unit
>
> Can just as easily be:
>
> func :: (MonadConsole m, MonadGimmeRandom m) => m ()
>
> (mangled name so it doesn't overlap with a real class)
>
> There are other differences, but they haven't amounted to much for me yet.
>
> Kmett's Quine has a good example of some homespun mtl-style:
> https://github.com/ekmett/quine
>
> On Wed, Oct 19, 2016 at 12:17 PM, Will Yager <will.yager at gmail.com> wrote:
>
> Can anyone comment on the use of Purescript-style effect monads as compared
> to MTL and Free? While I have not used them in practice, they seem to
> express the "intent" of monad composition a bit more directly than the
> approaches we use in Haskell.
>
>
> Cheers,
>
> Will
>
> _______________________________________________
>
> Haskell-Cafe mailing list
>
> To (un)subscribe, modify options or view archives go to:
>
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>
> Only members subscribed via the mailman list are allowed to post.
>
>
>
>
> --
> Chris Allen
> Currently working on http://haskellbook.com



-- 
Chris Allen
Currently working on http://haskellbook.com


More information about the Haskell-Cafe mailing list