[Haskell-beginners] Type of function with constant pattern
allbery.b at gmail.com
Wed Apr 11 04:07:08 CEST 2012
On Tue, Apr 10, 2012 at 20:53, <j.romildo at gmail.com> wrote:
> 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
> > 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
> > "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.
brandon s allbery allbery.b at gmail.com
wandering unix systems administrator (available) (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Beginners