suffixes :: [a] -> [[a]]
suffixes xs@(_:xs') = xs : suffixes xs'
suffixes _ = []
I only know that @ here is called "AsPattern". But how does it actually work here ? Is there anyone can give me a analysis?
And how does ! work in haskell. I can not give an example right now. But I am pretty sure it does occur in the haskell programming .
The @ symbol allows you to pattern match and refer to the entire value you are pattern matching against. In your example you can refer to the whole list argument as xs (using the @ symbol) and the tail of the list as xs' (using pattern matching).
The ! symbol can be used to force a value to be evaluated strictly instead of lazily (using bang patterns or strictness annotations).
In Haskell, you can use an As Pattern to give an argument an alternative name by which you can refer to it. In your case,
xs@(_:xs')
allows you to use xs as an alternative name for the argument (_:xs'). Otherwise, you wouldn't be able to do this because _ matches any argument, but is unusable otherwise.
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