On Tue, Apr 10, 2012 at 02:16:15PM -0700, Tim Perry wrote:
> I believe that "f 0 = ..." is a guard and the guard is pattern matching on
> the constructor. Despite the fact that you don't have an instance of "f _ =
> ....", the compiler needs an Eq instance to determine if it should run the
> "f 0" version of the function.
>
> Does that make sense? Hopefully someone with a better grasp of the topic
> will fill in the details.
I think you are using the wrong terms. The given examples does not make
any use of guards. Guards are boolean expressions attached to the right
It is using guards; you don't see them, because it's quietly translated by the compiler in the same way that `do` blocks are translated into applications of (>>=) and (>>) operators.
The reason for this is that numeric literals aren't actually literals; they are applications of the `fromInteger` function. This is true even in patterns; therefore they can't actually be matched as patterns but are translated into guards.
--