[Haskell-cafe] [Alternative] summary of my understanding so far

Alexander Solla alex.solla at gmail.com
Mon Dec 19 04:03:15 CET 2011


On Sun, Dec 18, 2011 at 6:44 PM, Gregory Crosswhite
<gcrosswhite at gmail.com>wrote:

>
> On Dec 19, 2011, at 12:39 PM, Brandon Allbery wrote:
>
> On Sun, Dec 18, 2011 at 20:42, Richard O'Keefe <ok at cs.otago.ac.nz> wrote:
>
>> No.  Not by a country mile.
>> It's better than "non-existent".
>> It's better than "misleading".
>> But it's not even on the same *continent* as "adequate".
>>
>
> +1
>
>
>
> So what do you all think about my own suggestion for the documentation?
>  The following is the same as what I've posted before, but with some tweaks
> such as swapping the last two paragraphs.
>
> ============================================================
>
> The Monoid instance for Maybe has the property that, for all x and y,
> (Just x) wins when combined (on either side) with Nothing values, and when
> (Just x) is combined with (Just y) then the result is (Just (x `mappend`
> y)).
>
> Note that the behavior of the Monoid instance of Maybe is *different* from
> the behavior of the MonadPlus and Alternative instance of Maybe.  For the
> latter two typeclasses, the behavior is that when (Just x) is combined with
> (Just y) the x and y values themselves are not combined but rather y is
> discarded so (Just x) simply wins;  put another way, for all x and z, we
> have that (Just x) `mappend` z is *always* equal to (Just x), regardless of
> whether z is equal to Nothing or whether it is equal to (Just y) for some
> y.  For this reason, unlike the instance for Monoid, the instances for
> these MonadPlus and Alternative place no additional constraints on the type
> lifted into Maybe.
>
> Incidentally, for the more mathematically inclined, you may think of this
> as being equivalent to the standard practice of turning an arbitrary
> semigroup into a monoid by simply adding a new element to the semigroup to
> serve as the identity element, where in this case the identity element is
> the Nothing value of Maybe;  unfortunately, since the base libraries do not
> come with a Semigroup typeclass, this process is expressed in code as
> lifting from the Monoid typeclass.
>
> ============================================================
>
> I welcome any feedback that you all have to offer.  If some iteration of
> the above is considered an improvement, then I would be happy to submit a
> patch using whatever process someone is kind enough to point me towards.
>  :-)
>
>
The "incidental" comment is significantly more clear than an English
description.

As somebody else has said in these threads, the problem is that
syntactically equivalent but semantically distinct types have been
collapsed into Maybe.  That complicates the reading of the source code,
since it is much harder to figure out which interpretation is intended, and
so which theorems we get from the types.  In other words, they are not free
theorems (since those are true in any interpretation).  We have to work for
them.

I would rather see commutative diagrams (or what amounts to the same, usage
examples) that describe the behavior than a "plain English" description.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111218/685662c9/attachment.htm>


More information about the Haskell-Cafe mailing list