aspatterns
Aspatterns are a feature of Haskell pattern matching that allow a value matched by a pattern to be simultaneously bound to a name and decomposed. The syntax uses the at symbol, as in name@pattern. When the pattern matches, the name refers to the entire matched value, while the components bound inside the pattern provide access to parts of the value. This is useful when a function needs to inspect parts of a value while also keeping a reference to the original value for further processing.
Common usage examples illustrate the idea. For instance, lengthAndHead xs@(y:_) = (length xs, y) binds xs to
Aspatterns are applicable in function equations and case expressions, enabling concise code that both analyzes and
Limitations and considerations include potential readability concerns if overused; alternatives such as separate bindings with let