Hi!
In Course/StateT, we are asked to implement an Applicative instance for OptionalT. I initially wrote the following:
---------------
(OptionalT f) <*> (OptionalT o) = OptionalT $ do
o' <- o
f' <- f
pure (f' <*> o')
------------------
This works for the first few tests, but fails eventually. One of the failed tests:
-----------------
testCase "six" $
let ot = OptionalT (Full (+1) :. Empty :. Nil) <*> OptionalT (Full 1 :. Full 2 :. Nil)
in runOptionalT ot @?= (Full 2 :. Full 3 :. Empty :. Nil
FAILED: 'StateT.(<*>) for OptionalT.six'
"Expected [Full 2,Full 3,Empty] but got [Full 2,Empty,Full 3,Empty]"
------------------
At first, I suspected this had to do with the difference between the two "modes" of Applicative on List: zip vs cartesian. But changing the Applicative instance for List in Course/Applicative--which I verified by reloading all loaded modules and running code that exercised it specifically in ghci--had no effect on the test failures.
Could someone explain why my solution doesn't work? Am I on the right track re: List Applicative?