Question: please write function in haskell data OpCode = Push Float Add | Mult | Sub | Div | Swap deriving Show The operations have the
data OpCode = Push Float Add | Mult | Sub | Div | Swap deriving Show The operations have the following effect on the operand stack. (The top of the stack is shown on the left.) T... OpCode Initial Stack Resulting Stack Push(r) Add a b... (b + a)... Mult a b... (b* a) Sub a b... (b-a) Div a b... (b / a) Swap ba... a b... We define the Stack data type as follows: type Stack - [Float] Please write function eval:: [OpCode), Stack) -> Float. It takes a list of operations and a stack and performs each operation in order then returns what is left in the top of the stack when no operations are left. For example, eval([Push 3.0, Push 1.0, Add], 0)) - 4.0 eval([Push 3.0, Push 1.0, Sub], []) - 2.0 If the inputs are illegal, the result should be 0.0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
