[Haskell-cafe] Associated Type Synonyms question

Niklas Broberg niklas.broberg at gmail.com
Sun Feb 12 15:32:14 EST 2006

On 2/10/06, Ross Paterson <ross at soi.city.ac.uk> wrote:
> On Fri, Feb 10, 2006 at 05:20:47PM +0100, Niklas Broberg wrote:
> > - when looking at the definition of MonadWriter the Monoid constraint
> > is not strictly necessary, and none of the other mtl monads have
> > anything similar. Is it the assumption that this kind of constraint is
> > never really necessary, and thus no support for it is needed for ATS?
> I think that's right -- it's only needed for the Monad instance for
> WriterT.  But it is a convenience.  In any instance of MonadWriter, the
> w will be a monoid, as there'll be a WriterT in the stack somewhere,
> so the Monoid constraint just saves people writing general functions
> with MonadWriter from having to add it.

Sure it's a convenience, and thinking about it some more it would seem
like that is always the case - it is never crucial to constrain a
parameter. But then again, the same applies to the Monad m constraint,
we could give the same argument there (all actual instances will be
monads, hence...). So my other question still stands, why not allow
constraints on associated types as well, as a convenience?

Irrelevant to the discussion above, but I wonder whether the Monoid
constraint should really be there on MonadWriter. I could imagine lots
of interesting applications of writer monads that don't output a
monoid, an example would be a monad that iteratively computes a result
of better and better precision and "tells" the result of each step
until told to stop. In this case the merging would not be mplus but to
always throw away the old argument (flip const).
But then again you could always keep the results in a list and only
use the last element... :-)


More information about the Haskell-Cafe mailing list