In addition to a guard attached to a pattern, pattern guard can refer to the use of pattern matching in context of a guard. In effect, a match of the pattern is taken to mean pass. This meaning was introduced by a proposal for Haskell by Simon Peyton Jones titled A new view of guards in April 1997 and has been further used about the implementation of the proposal. The feature provides the possibility to use patterns in the guards of a pattern.
An example in the extended Haskell:
clunky env var1 var2 | Just val1 <- lookup env var1, Just val2 <- lookup env var2 = val1 + val2 -- ...other equations for clunky...This would read: "Clunky for an environment and two variables, in case that the lookups of the variables from the environment produce values, is the sum of the values. ..." Like in list comprehensions, the guards are in series, and if any of them fails the branch is not taken.
Read more about this topic: Guard (computer Science)
Famous quotes containing the words pattern and/or guard:
“The real trouble about women is that they must always go on trying to adapt themselves to mens theories of women, as they always have done. When a woman is thoroughly herself, she is being what her type of man wants her to be. When a woman is hysterical its because she doesnt quite know what to be, which pattern to follow, which mans picture of woman to live up to.”
—D.H. (David Herbert)
“Be on guard so that your hearts are not weighed down with dissipation and drunkenness and the worries of this life, and that day catch you unexpectedly, like a trap.”
—Bible: New Testament, Luke 21:34.35.