[Haskell-cafe] What's the advantage of writing Haskell this way?

Casey McCann syntaxglitch at gmail.com
Mon May 30 16:53:17 CEST 2011

On Mon, May 30, 2011 at 9:01 AM, John Ky <newhoggy at gmail.com> wrote:
> instance Monoid (Stream a) where
>     mempty = Chunks mempty
>     mappend (Chunks xs) (Chunks ys) = Chunks (xs ++ ys)
>     mappend _ _ = EOF
> I guess, it shows my lack of experience in Haskell, but my question is, why
> is writing the code this way preferred over say writing it like this:

I don't care for the inconsistency in this example, using both mempty
and (++). Your version is at least consistent, but I'd actually prefer
to use mappend instead of (++) here, because it makes it clear that
this isn't actually defining a "new" Monoid instance, just translating
an existing instance for the constructor parameter to work for the
surrounding data type.

- C.

More information about the Haskell-Cafe mailing list