PureScript Edition
A set of challenges for jump starting your understanding of monads.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
As with the previous set, you will want to create a Monad
instance for your Maybe
data type.
Once that is accomplished, rewrite the following functions using do syntax:
queryGreek :: GreekData -> String -> Maybe Double
addSalaries :: Array (Tuple String Int) -> String -> String -> Maybe Int
tailProd :: forall a. Semiring a => Array a -> Maybe a
tailSum :: forall a. Semiring a => Array a -> Maybe a
tailMax :: forall a. Ord a => Array a -> Maybe a
You should import Set2 so that you can use the helper functions you wrote in that set.
You can test queryGreek
with the following assertions:
queryGreek greekDataA "alpha" == Just 2.0
queryGreek greekDataA "beta" == Nothing
queryGreek greekDataA "gamma" == Just 3.3333333333333335
queryGreek greekDataA "delta" == Nothing
queryGreek greekDataA "zeta" == Nothing
queryGreek greekDataB "rho" == Nothing
queryGreek greekDataB "phi" == Just 0.24528301886792453
queryGreek greekDataB "chi" == Just 9.095238095238095
queryGreek greekDataB "psi" == Nothing
queryGreek greekDataB "omega" == Just 24.0