suggestion: use lazy pattern matching for Monoid instances of tuples
Henning Thielemann
schlepptop at henning-thielemann.de
Sat Aug 17 22:40:50 CEST 2013
Am 17.08.2013 22:31, schrieb Petr Pudlák:
> Dear haskellers,
>
> currently the instances are defined as
>
> |instance (Monoid a,Monoid b) =>Monoid (a,b)where
> mempty = (mempty, mempty)
> (a1,b1) `mappend` (a2,b2) = (a1 `mappend` a2, b1 `mappend` b2)|
I think that this instance is correct, since it must hold
forall x. mappend mempty x = x
With your instance you get for x=undefined:
mappend mempty undefined = (undefined, undefined)
However, the "instance Monoid ()" is too lazy, such that it does not
satisfy the identity law.
More information about the Libraries
mailing list