qfpl / applied-fp-course

Applied Functional Programming Course - Move from exercises to a working app!
http://qfpl.io/projects/professional-fp-courses/
Other
625 stars 180 forks source link

Tests now working? #66

Closed dmvianna closed 6 years ago

dmvianna commented 6 years ago

I have now completed the exercises in this repo (at least they compile...). However Since very early in the Levels, running cabal new-test test-suite:app-fp-tests within nix-shell (nixos) gives me

Test suite app-fp-tests: RUNNING...

and nothing more. Uncommenting each Level separately doesn't change that behaviour.

With cabal test test-suite:app-fp-tests I get instead

cabal: no such test: test-suite:app-fp-tests

and finally, with cabal test app-fp-tests and cabal new-test app-fp-tests I get the same behaviour as with cabal new-test.

Notice that this happens only when I complete each Level. I get proper error messages before completing a level.

mankyKitty commented 6 years ago

When you say "and nothing more", do you mean that the tests hang indefinitely, or do they complete without providing any errors?

Have you tried introducing something you know would fail the tests so you can see what might happen?

dmvianna commented 6 years ago

Yes, it hangs indefinitely as if it were running the app. You can check my code. No, I didn't introduce anything to make it fail (although it does until I remove the error statements such as)

error "Copy your completed 'app' from the previous level and refactor it here"
mankyKitty commented 6 years ago

You still have undefined in https://github.com/dmvianna/applied-fp-course/blob/dmvianna/src/Level06/Core.hs#L61 so even when you fix issue the tests will still fail.

The issue arises from your MonadIO instance for AppM, you are using liftIO to try to lift a function from IO to AppM, when that is the function you are actually trying to implement. You do not need to use liftIO in this definition, look again the types you are working with:

You start with:

IO a

You want:

AppM a

The constructor for AppM requires:

IO (Either Error a)

So if you start your implementation with something like:

liftIO :: IO a -> AppM a
liftIO ioa = AppM (_F ioa)

That type hole _F will tell GHC to give you some more information about what is required, you should be able to then follow the types to arrive at a solution.

I would also suggest, that for each of these typeclasses, comment out your current solution and then try to reimplement them using only functions from that typeclass.

You don't need Monad or MonadIO to write the Functor instance, for example.

dmvianna commented 6 years ago

Thank you @mankyKitty! All sorted. I really needed a refresher on writing sane instances! What got into my head!

dmvianna commented 6 years ago

What's the next challenge from qfpl? Reflex?

mankyKitty commented 6 years ago

That, and so much more. ;)