Reputation: 33
step :: [Int] -> String -> [Int]
step :: (Num a, Read a) => String -> a
step = head . foldl foldingFunction [] . words
where foldingFunction (x:y:ys) "*" = (x * y):ys
foldingFunction (x:y:ys) "+" = (x + y):ys
foldingFunction (x:y:ys) "/" = (x / y):ys
foldingFunction (x:y:ys) "-" = (y - x):ys
foldingFunction xs numberString = read numberString:xs
The code above keeps giving this error: I have tried to fix it by changing step to solveRPN and tried taking out the square brackets [], but i keep getting this error.
haskell.hs:4:1: error: parse error on input ‘where’
|
4 | where foldingFunction (x:y:ys) "*" = (x * y):ys
| ^^^^^
Failed, no modules loaded.
Upvotes: 1
Views: 100
Reputation: 64750
There are a number of problems here.
step :: ...
twice, pick one signatures and delete the other.where
must be indented.Upvotes: 6