being new to haskell I decied to try and implement a mini reverse polish notation function:
Takes in a list
of type int
and a string operator ('*','+','/','-'
)
apply the operator to the tail
element and the tail-1
element
return the resultant list
with the two elements involved in the operation popped off and the resultant element appended to the tail as such:
Where e0 = original element at index 0
r = result of the operation:
result = [e0,e1,e2...r] (elements popped off: eN, eN-1)
This is the code I have so far:
import Data.List
import System.IO
step :: [Int] -> String -> [Int]
step stack operator
| (x:y:ys) "*" = (x * y):ys
| (x:y:ys) "+" = (x + y):ys
| (x:y:ys) "-" = (x - y):ys
| (x:y:ys) "/" = (x / y):ys
And it gives me the following compile error:
• Couldn't match expected type ‘[Char] -> Bool’
with actual type ‘[a3]’
• The function ‘x : y : ys’ is applied to one argument,
but its type ‘[a3]’ has none
In the expression: (x : y : ys) "/"
In a stmt of a pattern guard for
an equation for ‘step’:
(x : y : ys) "/"
I believe this is the result of an error in my syntax, any help is welcome!