Question: Please I need help with the stack implementation in haskell. I need to create two functions for the respective a and b part. 9. [26
Please I need help with the stack implementation in haskell. I need to create two functions for the respective a and b part.


9. [26 = 8 + 18 points] The following definitions are for a stack of values with operations push and pop type Stack a[a] data stackop a = Push a | Pop deriving (Eq, Show) type config a = (Stack a, [Maybe a]) -A configuration is the current stack and list of Pop results a. [8 points] Define a function apply Stackop a -> Config a -> Config a Applying (Push x) (Config stack results) add (i.e., cons) x onto the stack and Nothing onto the results. If the stack has head x, then Pop removes x from the stack and adds Just x to the results. . If the stack is empty, then Pop simply adds Nothing to the results b. [18 points] Define a function applyList Stackop a] -> Config a applyList should take a list of stack operations and apply them in sequence to the starting hhasanempy ak and empty list of resuls) Four of the points are for defining applyList not recursively but using higher-order functions like map and foldl. (So applyList ops =functional expression.) [If you can't write it this way, write it tail-recursively. [9/3] Hint: Write an applyList' ops config helper function that applies the operations to the config and returns the resulting config. 9. [26 = 8 + 18 points] The following definitions are for a stack of values with operations push and pop type Stack a[a] data stackop a = Push a | Pop deriving (Eq, Show) type config a = (Stack a, [Maybe a]) -A configuration is the current stack and list of Pop results a. [8 points] Define a function apply Stackop a -> Config a -> Config a Applying (Push x) (Config stack results) add (i.e., cons) x onto the stack and Nothing onto the results. If the stack has head x, then Pop removes x from the stack and adds Just x to the results. . If the stack is empty, then Pop simply adds Nothing to the results b. [18 points] Define a function applyList Stackop a] -> Config a applyList should take a list of stack operations and apply them in sequence to the starting hhasanempy ak and empty list of resuls) Four of the points are for defining applyList not recursively but using higher-order functions like map and foldl. (So applyList ops =functional expression.) [If you can't write it this way, write it tail-recursively. [9/3] Hint: Write an applyList' ops config helper function that applies the operations to the config and returns the resulting config
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
