Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Guard (computer science)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Pattern guard== In addition to a guard attached to a pattern, '''pattern guard''' can refer to the use of [[pattern matching]] in the context of a guard. In effect, a match of the pattern is taken to mean pass. This meaning was introduced in a proposal for Haskell by [[Simon Peyton Jones]] titled [https://web.archive.org/web/20160203203811/http://research.microsoft.com/en-us/um/people/simonpj/Haskell/guards.html A new view of guards] in April 1997 and was used in the implementation of the proposal. The feature provides the ability to use patterns in the guards of a pattern. An example in extended Haskell: <syntaxhighlight lang="haskell"> clunky env var1 var2 | Just val1 <- lookup env var1 , Just val2 <- lookup env var2 = val1 + val2 -- ...other equations for clunky... </syntaxhighlight> This would read: "Clunky for an environment and two variables, ''in case the lookups of the variables from the environment produce values'', is the sum of the values. ..." As in [[list comprehension]]s, the guards are in series, and if any of them fails the branch is not taken.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)