[Haskell-cafe] Re: Field names
Mauricio
briqueabraque at yahoo.com
Mon Sep 8 21:37:17 EDT 2008
> abs (Pt {pointx = x, pointy = y}) = sqrt (x*x + y+y)
>
>
> Why is it pointx=x and not x=pointx?
>
Your intuition is probably telling you that this
is something like:
abs (point) = sqrt (x*x+y*y)
where {x=pointx point ; y=pointy point}
Actually, it's an example of pattern matching:
abs (Pt {pointx=3 , pointy=4}) = 5
abs (Pt {pointx=3 , pointy=y}) = sqrt (9+y*y)
abs (Pt {pointx=z , pointy=z}) = (sqrt 2)*z
etc.
Best,
Maurício
More information about the Haskell-Cafe
mailing list