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

Lyndon Maydwell maydwell at gmail.com
Mon May 30 16:59:57 CEST 2011

I just tried to use the generic form with (Maybe a) and 'mconcat'
prevented this from working, so that needs to be considered too.

On Mon, May 30, 2011 at 10:53 PM, Casey McCann <syntaxglitch at gmail.com> wrote:
> 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.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list