[email protected]
[Top] [All Lists]

Re: [Haskell-cafe] Mysterious factorial

Subject: Re: [Haskell-cafe] Mysterious factorial
From: Ralf Hinze
Date: Wed, 30 Dec 2009 19:15:36 +0100
> I would use:
> 
> foldm :: Monoid m => [m] -> m
> 
> Which is just a better implementation of mconcat / fold.  The reason I
> prefer this interface is that foldm has a precondition in order to
> have a simple semantics: the operator you're giving it has to be
> associative.  I like to use typeclasses to express laws.

That's a valid point. Unfortunately, Haskell is not Coq, so there
is no guarantee that the monoid laws are actually satisfied. And
using a type-class has the downside that you can have only one
instance per type. Maybe, you want to use both `foldm (+) 0' and
`foldm (*) 1'. So the bottom-line is that you should have both
versions.

Cheers, Ralf
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

<Prev in Thread] Current Thread [Next in Thread>