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

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to