Search code examples
haskellsyntaxsymbols

What is the meaning of the '@' operator in Haskell


I have this code:

  mix xxs@(x:xs) yys@(y:ys)
  | x<=y = x : mix xs yys
  | otherwise = y : mix xxs ys

But I don't know what the @ means.


Solution

  • It's not an operator; it's part of the pattern syntax. In the case of yys@(y:ys), if the second argument successfully matches against (y:ys), the entire value matched is bound to yys as well.

    So, if you called min [1,2] [3,4], then y would be bound to 3, ys to [4], and yys to [3,4].