Conor McBride ctm at Cs.Nott.AC.UK
Mon Oct 23 15:19:12 EDT 2006

Ross Paterson wrote:
> On Mon, Oct 23, 2006 at 01:15:46PM -0400, Samuel Bronson wrote:
>> On 10/22/06, John Meacham <john at> wrote:
>>> Although, now that we lost the Monoid instance for functions (which is
>>> very dismaying), it is less useful, as the monoid functions were very
>>> useful to build things up efficiently with (String -> String) as a type.
>> WHAT!!!!
>> Who, when, where, why, how????

Funnily enough, that was my reaction when I saw that endofunctions under
composition /was/ the library instance of Monoid for functions, thus
preventing the powerful 'pointwise lifting' instance...

> The function composition instance is now wrapped in a newtype.
> The instances available now are listed here:
> I was who; here is some of the rest:

...which we now have instead, allowing things like

newtype Parser a = Parser (String -> [(a, String]) deriving Monoid

and plenty of other goodies. I have code (part of the Epigram layout
library) which systematically iterates pointwise lifting to jack up
operators on text boxes to operators on prioritised streams of text
boxes, monoidal with respect to a lossy merge operation which discards
obviously bad layouts and prevents combinatorial explosion. Pointwise
lifting is one way to keep the programs simple even when the underlying
structures become complex.

While we're at it, would anybody object to a few other instances of the
same idea?

for <blah> in {State s, IO, Id}, may we have suitable Applicative
instances where currently absent, then

> instance Monoid x => Monoid (<blah> x) where
>   mempty         = pure mempty
>   mappend sx sy  = pure mappend <*> sx <*> sy


Basically, I'd suggest that any monad/idiom/whatever should lift monoids
if it doesn't induce a monoid structure of its own (as [], Maybe, etc)
do. What to do with StateT etc is more complex...

Does this make sense?



This message has been checked for viruses but the contents of an attachment
may still contain software viruses, which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

More information about the Libraries mailing list