I am a newbie in Haskell and hope this question is not silly.
I have seen so much example that when I am having a list, I am able to match and bind "composition element" of the list to individual variable:
listSizeDesc :: [a] -> String
listSizeDesc [] = "Emtpy"
listSizeDesc (x:xs) = "Something inside"
However, I tried to do something like:
foo :: Int -> String
foo 0 = "Zero"
foo (n - 1) = "next number is " ++ show n
It doesn't work.
It seems to me that both (n-1) and (x:xs) describe how the argument is "created" and bind the "component" to an argument. Is the way List matched specially designed for ease of recursion? Coz it seems to me this matching / argument-binding logic doesn't apply to other functions except (:).
Maybe
. – Joachim Breitner