[Haskell-cafe] MTL vs Free-monads, what are your experiences
will.yager at gmail.com
Wed Oct 19 18:41:52 UTC 2016
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.
> 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:
>> 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.
>> Haskell-Cafe mailing list
>> To (un)subscribe, modify options or view archives go to:
>> Only members subscribed via the mailman list are allowed to post.
> Chris Allen
> Currently working on http://haskellbook.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe