[Haskell-cafe] MTL vs Free-monads, what are your experiences
Heinrich Apfelmus
apfelmus at quantentunnel.de
Sun Oct 16 08:22:37 UTC 2016
> My gut feeling is that an an indirect function call for every (>>=),
> with many calls to `lift` each time, would make a deep monad
> transformer stack much more expensive. A free monad approach seems to
> be more sensible to me. But maybe GHC is doing a better job optimizing
> this than I would think?
Well, my gut feeling would be that free monads are more expensive than a
monad transformer stack with <= 3 layers. After all, for
free/operational monads, the compiler has to allocate a closure for
every second argument of `>>=` as part of the monad data structure.
There are less opportunities for inlining, because the interpretation of
the monad is not fixed, and only decided late at runtime.
That said, the above arguments are no proof. I would be interested in
performance measurements as well.
Maybe there is a way to generalize the "GHC state hack" to a "free monad
hack"? The basic ansatz would be the ability to mark some closures as
"Only entered once, may duplicate work".
Best regards,
Heinrich Apfelmus
--
http://apfelmus.nfshost.com
Joachim Breitner wrote:
> Hi,
>
> Am Freitag, den 14.10.2016, 17:35 +0200 schrieb Damian Nadales:
>> Do you have
>> any experience using any of these approaches. If so would you mind
>> sharing? ;)
>
> I don’t have an answer to contribute, but I would be very interested in
> hearing about experiences in terms of their relative runtime
> performance.
>
> My gut feeling is that an an indirect function call for every (>>=),
> with many calls to `lift` each time, would make a deep monad
> transformer stack much more expensive. A free monad approach seems to
> be more sensible to me. But maybe GHC is doing a better job optimizing
> this than I would think?
>
> So if you have any number-supported evidence about this, possibly from
> a real-world application where you tried to use one or the other,
> please share it with us!
>
> Thanks,
> Joachim
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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.
More information about the Haskell-Cafe
mailing list