On Mon, May 30, 2011 at 9:01 AM, John Ky <newho...@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.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to