Hacker News new | ask | show | jobs
by angeladur 5086 days ago
What does getSquare (Math _ square _) = square mean?
1 comments

That's a pattern match. Math is a data constructor, it makes a Math object. It takes three arguments. So (Math 1 2 3) is a Math object.

A pattern is a way of deconstructing an object into its constituent parts and bringing some of those into scope.So (Math x y z) is a valid pattern, which would bring these values into scope: x=1, y=2, z=3. In this case I'm bringing only the second argument into scope. In a pattern, _ means "ignore this argument".

Here is a short interactive lesson on pattern matching: http://tryhaskell.org/#19