moocfi/haskell-mooc

Lecture 13 - Example function does not do the expected

hekazu opened this issue · 1 comments

In 13.1, (?>) is introduced. This is then used to make the function increase look better. However, this new version of the function is not correct. The current and new value comparison is flipped, i.e. x < val instead of the expected val < x from the original example.

The full block of code where the issue is present for further clarity:

increase :: Eq a => a -> Int -> [(a,Int)] -> Maybe [(a,Int)]
increase key val assocs =
    lookup key assocs ?>
    check ?>
    buildResult
  where check x
           | x < val   = Nothing
           | otherwise = Just x
        buildResult x = Just ((key,val) : delete (key,x) assocs)

thanks for noticing that!