Question: Consider a function that takes an integer and adds two, but only if it is positive. If the input is zero or less, then that
Consider a function that takes an integer and adds two, but only if it is positive. If the input is zero or less, then that is an error. Write this function as a Haskell function, handling the error in the functional way.
f x if x then x else Null
f x if x then x else error "invalid input"
f x if x then Just x else Nothing
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
