Question: Can someone assist me with this Haskell Programming problem? The evaluator crashes in cases where there are bad inputs and division by zero. This isnt

Can someone assist me with this Haskell Programming problem?

The evaluator crashes in cases where there are bad inputs and division by zero. This isnt particularly useful for recovery purposes. We can refactor the evaluator by using the data type, Result a b, to allow us to return a valid result or a failure indicator. Note the following code (from RPNAST.hs): data RPNError = DivByZero | BadSyntax deriving ( Show , Eq ) data Result a b = Failure a | Success b deriving ( Show , Eq ) type RPNResult = Result RPNError Int By convention, the data type, Result a b, is either the failure case (i.e., Failure a) or the success case (i.e., Success b). Write a function called prob3, that has the type PExp -> RPNResult.

Hint: you may need to define a helper function that takes a stack and a PExp and returns an RPNResult. Use this helper function to define prob3.

Note: the error function in Haskell (a hack of sorts) crashes the program and isnt catchable in a pure function. Here are examples of how prob3 should work:

Can someone assist me with this Haskell Programming problem? The evaluator crashes

And here is the file that contains the types PExp and RPNError

in cases where there are bad inputs and division by zero. This

Homework3*> prob3 [Val 5, Val 0, IntDiv Failure DivByZero Homework3*> prob3 [IntDiv, Plus, Val 0] Failure InvalidInput Homework3 prob3 [Val 5, Val 1, Val 1, Plus, Mul] Success 10 Homework3*> prob3 [Val 5, Val 0, IntDiv Failure DivByZero Homework3*> prob3 [IntDiv, Plus, Val 0] Failure InvalidInput Homework3 prob3 [Val 5, Val 1, Val 1, Plus, Mul] Success 10

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!