My question regards the code in the Answer of the question at Haskell - Reverse polish notation regular expression to expression tree. I've duplicated the code here so you needn't follow the above link:
data Tree
= Symbol Char
| Op Char Tree Tree
deriving Show
type Stack = [Tree]
step :: Stack -> Char -> Stack
step (r:l:s) '.' = (Op '.' l r):s
step (r:l:s) '+' = (Op '+' l r):s
step s c = (Symbol c):s
parse :: String -> Stack
parse = foldl step []
I put the code above in a file, added main that calls parse with arg "aa.bb.+" and got result matching that at the original question.
My question: How does parse work if its 1st arg (the expression to be parsed) is ignored? How can step work if it doesn't receive its second arg?
In my file I replaced:
parse = foldl step []
with:
parse s = foldl step [] s
Resulting program also works correctly and seems "more correct" since parse now uses its arg.