transformers versus mtl

Iavor Diatchki iavor.diatchki at gmail.com
Sat Mar 21 18:05:57 EDT 2009


Hello,
There are a number of reasons why I prefer monadLib over mtl.  None of
them are huge issues, which is why I never bothered to "spread the
word" :)  Anyway, here are some of the differences off the top of my
head (not in order of importance)
  - Nicer packaging: monadLib has 1 module (or 3 depending on how you
look at it), mtl has 21
  - Conceptually simpler types:  monadLib provides two base mondas (Id
and Lift) and one transformer per effect.  By combining these
programmers can construct all the monads that they need.  MTL also
provides these, but in addition it provides other types which I think
are unnecessary and make things look more complex then they are (RWS
monad, strict/lazy version of monads, predefined base monads)
  - Correct back-tracking transformer, called ChoiceT.  At least in
the past MTL's ListT worked only for commutative monads, I am not sure
if that was fixed.
  - In monadLib one can throw arbitrary exceptions (there is no need
for an Error class). I never understood what's the point of the class
Error.
  - MonadLib has a more general "MonadIO" class, called "InBase".  It
allows executing computations in the base monad of a tower of monads,
even when the base monad is not IO.
  - MonadLib organizes the different effect operators in a slightly
different hierarchy of classes which, in principle, allows for more
fine-grained control over effect (e.g., you could have a type that
ensure that a computation will only raise exceptions but not handle
them).

I think that's probably about it.  As I said, none of these are huge
issues, indeed monadLib was originally designed to replace mtl, so
they are fairly similar in style and appearance.  This never happened
because it was in the early days of Haskell libraries and we had no
good process for doing things like that.  Also, I am not that
interested in marketing :-)

On Ganesh's question if monadLib could be written in terms of
"transformers":  no, because transformers uses a different list
transformer.  Furthermore, I would not be inclined to do it because it
would add an extra unnecessary dependency to monadLib, and also I
think that transformers has some of the same problems as mtl (17
modules, some of which define things like RWS).

Apologies if was too critical of MTL, I think that it is a fine
library which is clearly used by many people.  I just think that
monadLib is a bit nicer.

-Iavor



On Fri, Mar 20, 2009 at 1:16 AM, Sittampalam, Ganesh
<ganesh.sittampalam at credit-suisse.com> wrote:
> Duncan Coutts wrote:
>> On Thu, 2009-03-19 at 16:39 -0700, Iavor Diatchki wrote:
>>> Hello,
>>>
>>> I would like to point out that another option is monadLib, which has
>>> been around for a while.   It was never marketed very much so it
>>> never become particularly popular but it works pretty well (my
>>> colleagues and I use it on a number of projects).
>>
>> Can you market it a bit more please :-). Tell us what the advantages
>> of it are over mtl.
>
> Also, is there any scope for eliminating duplication by depending on
> transformers for the common datatypes etc? I'm sure monadLib has its
> own distinctive features but for those parts that are the same I feel
> we really should be trying to avoid incompatibilities.
>
> Cheers,
>
> Ganesh
>
> ===============================================================================
>  Please access the attached hyperlink for an important electronic communications disclaimer:
>  http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
>  ===============================================================================
>
>


More information about the Libraries mailing list