[Haskell-cafe] [Alternative] change some/many semantics

Antoine Latter aslatter at gmail.com
Thu Dec 15 10:06:23 CET 2011


On Thu, Dec 15, 2011 at 2:20 AM, Gregory Crosswhite
<gcrosswhite at gmail.com> wrote:
>
> On Dec 15, 2011, at 6:19 PM, Gregory Crosswhite wrote:
>
> After all, we already have the Monad typeclass which gives them essentially
> the same functionality.
>
>
> Make that the *Monoid* typeclass.  :-)

And this is an interesting discussion all of its own!

Should the monoid instance of a Functor do what List does - which is
analogious to its append or choice operation (where applicable), or
should it do what Maybe does, which is lift the operation into its
contained type? (That is, (Just x) `mappend` (Just y) ==> Just (x
`mappend` y)).

Since the Monoid instance for Maybe doesn't offer choice between
Nothing and Some, it would be nice to have a standard choice operation
that we could use for Maybe.

Which is sort of what Alternative is - offering choice over a functor
which supports it. Except that the notion of what choice means is
richer in a parser than in Maybe (parsers may backtrack (like List)
and parsing has some sort of stateful effect, which affects the
success of future parses).

It is an interesting dilemma.

I am also fond of using Alternative (disguised as MonadPlus) in the
Happstack sense, for building a web-site routing table. In the truest
sense I am composing alternative responses to an input request, but
using 'many', 'some', or 'sepEndBy` in this context would be odd.

Antoine



More information about the Haskell-Cafe mailing list