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.
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].
This is an as-pattern [Haskell tutorial] it is used to have a reference both to the entire list xxs, the head of the list x and the tail of the list xs (and of course the same for the second list).
The pattern will only fire if all the subpatterns match as well, so in this case if both the two lista re non-empty. It is often used as an optimization, since now you can use the first or second parameter xxs or yys in the body of the function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With