I\'m reading through Real World Haskell, and am trying to understand the as-pattern.
From the book (Chapter 4):
suffixes :: [a] -> [[a]]
suffixes
xs'
would be bound to the string "ello"
.
xs
would be bound to the string "hello"
.
The @
pattern lets you give a name to a variable while also matching its structure and possibly giving name to the components.
Perhaps an actual "de-sugaring" will make it easier to understand:
suffixes xs@(_:xs') = xs : suffixes xs'
is equivalent to
suffixes xs
| (_:xs') <- xs = xs : suffixes xs'
i.e. you're firstly binding the entire argument to the variable xs
, but you also do pattern matching on the same argument (or, equivalently, on xs
) to (_:xs')
.