1
1
mirror of https://github.com/qfpl/applied-fp-course.git synced 2024-11-26 14:43:53 +03:00
applied-fp-course/INSTRUCTOR_NOTES.md
Sean Chalmers ef0b4aa3f5 Updates based on course run feedback.
Levels 3,4, and 5 have been reordered for a better flow and more constructive
exercises.

All levels should now build on GHC versions: {7.10.3, 8.0.2, 8.2.2}

TravisCI integration added for GHC version build testing.

Probably broke a whole bunch of things in the process. *sadface*

Squashed commit of the following:

commit 203a71de3b6df2525160e76622ce846053719ddf
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Tue Jan 16 12:33:23 2018 +1000

    Updated instructor notes, added important section for things to mention/ask

commit c8934debe9742d8ef7112ee661af7ebd3c58c7fa
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Tue Jan 16 12:14:24 2018 +1000

    Attempt to fix weird doctest bug for level05

    One more try at travis config for the time being.

commit 85cd8a23d0d180bbd49dc5b4a40361c1bae3921d
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Tue Jan 16 11:59:08 2018 +1000

    Deps updates and instructor notes added

commit 7898c2294f9303b89e82dd95a9714cbf6546f9b4
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Mon Jan 15 21:20:55 2018 +1000

    Removed import of Conf from Tests on level 03

commit 9c387e90ec4142bb02dd70bdee8752b7d5779c01
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Mon Jan 15 20:52:24 2018 +1000

    Removed other cabal check, add FirstApp.Conf to level 3 exposed modules

commit 2fe47b1cb46c240a9f5da6286af161724f334806
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Mon Jan 15 18:40:14 2018 +1000

    Bump doctest bounds

commit 7ede0c8b9f50fa12c6d240a9778672a75ad44bfe
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Mon Jan 15 18:16:53 2018 +1000

    Added semigroups as a dependency

commit 0d4c8e6539172487f9e2d239b74c8675ccf557dd
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Mon Jan 15 17:48:09 2018 +1000

    CI Fixes

    - Remove sdist packaging test from travis.yml as we're not going to ever put
      these on hackage.

    - Move lower bound on time library out further for older GHCs.

commit 20053d48780451edc8b8072bf23cfd3801935795
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Mon Jan 15 16:11:45 2018 +1000

    Expanding notes

commit 8d2e40012585828ede4ca8d506f71d504df690f9
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Mon Jan 15 15:55:30 2018 +1000

    Expanded bounds for base & time to try to cover more GHC versions. Updated project paths in travis script

commit d4cf006bed5cc925084a26afad159ef6442b1a4c
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Mon Jan 15 15:35:49 2018 +1000

    Removed older GHC versions that won't be tested against for now

commit 6543e1368ca179331ac25b141482b8cdb1a14d55
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Mon Jan 15 14:56:21 2018 +1000

    Generated Travis.yml using multi-ghc-travis. Added tested-with setting to cabal files. Added cabal project file.

commit b2ccf351abaebf62a33eef2f1f062eb081c31a29
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Mon Jan 15 14:34:52 2018 +1000

    Updated Level 07

    Use the new config structure.

    Expand the number of functions that need to be reworked because of the
    change to using ExceptT. Most involve copying previous answers, unsure
    if this will be a problem for people that aren't keeping up...

commit 6628e221488c1ed16b06b759009a4d7613bba5ea
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Mon Jan 15 13:52:29 2018 +1000

    Update Level06

    Expand on what is to be completed in level 06 with respect to refactoring
    functions to run in a ReaderT.

    Added the new Conf structure

commit 2cbc9ff269d3e204d340a266ab472d27fbf51e7e
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Mon Jan 15 10:59:30 2018 +1000

    Some minor adjustments for levels 6 & 7, fell out of sequence of larger changes

commit 3e964efc0b3c999930c2bfe8c69b13b63967da45
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Mon Jan 15 10:55:52 2018 +1000

    Reordered Levels {3,4,5}.

    The new order is:
    3) Testing (was #4)
    4) Database (was #5)
    5) Config (was #3)

    This flows better with an expected wind down into the testing level
    which is not very complex. Before increasing in difficulty again with
    the Database and then external config level.

    Still TODO:
    - Find what I missed when rewriting the parts of these levels that fell
    out of sync with the new ordering.

    - Update levels 6 & 7 to use the new configuraton structure from #5.

commit 67451fffd23b06fe7ae24905c11b1e8e3b8bf279
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Mon Jan 15 09:03:46 2018 +1000

    Fix time package version bound.

    Time version bound upped to 1.8.* for sqlite* packages.

    Stubbed out prepareAppReqs on level07.
    Removed lingering Table type on the db config.

commit de7ba8c88c83b5a4cf898f9f882f60721d804b07
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Mon Jan 15 08:45:41 2018 +1000

    Apply latest round of changes from feedback.

    !DONE drop the "do your own thing" from the README regarding build environments
    !DONE notes about how to test the end points using CURL (4-5 requests, mix of okay & fail)
    !DONE move 'parseOptions' towards the bottom of the file (because we export it)
    !DONE add import of Data.Bifunctor (first) to Conf
    !DONE use 'try' instead of 'catch' for readObject
    !DONE add comments for some tests to write for the application
    !DONE - testing empty comments etc
    !DONE - make the test for helloMsg the last test
    !DONE change the instructions in the readme for level05 to go from DB/Types to Types to DB
    !DONE remove the Table name interpolation from the Level05
    !DONE add the SQL into the functions for people.
    !DONE change the capitalisation of the Db/DB to be consistent across files (level05)
    !DONE fix instruction for modFieldLabel to not include camel-casing instructions
    !DONE add more information to the level05 Main.hs for 'prepareAppReqs' function.
    !DONE add explicit import for IOError (System.IO.Error)
    !DONE move the optparse-applicative out, students won't complete this section. Mention it as a thing to look at.
    !DONE Remove 'Conf.Conf' from 'handleRequest' from level >=5
    !DONE Add instruction to the end of AppM to send people onwards to FirstApp/Main.
    !DONE Add type signatures to the functions in the where clause in the FirstApp/Main (level06)
    !DONE Add type signature to 'toStartUpErr' function in level07
    !DONE !IMPORTANT! Remove/Fill in the 'flushTopic' function

commit f40cf697fd7ea87ecf187ce3368ccfcde61cdadf
Author: Sean Chalmers <sean.chalmers@data61.csiro.au>
Date:   Wed Jan 10 17:11:35 2018 +1000

    Start trying to rearrange conf to be a bit more friendly
2018-01-16 12:36:57 +10:00

4.9 KiB

Compilation of instructions and important things to remember for the different levels.

Level 1

We're going to be building an extremely simple web server using the 'wai' framework. Wai is a low level HTTP implementation similar to WSGI in Python or Rack in Ruby.

  • Hackage
    • Primary repository for Haskell packages and their documentation.
    • Package Index is extremely useful for discovering and interrogating packages.

Level 2

We're going to start building our own REST application by converting our "spec" into a data structure that will guide the construction of the rest of the application.

We'll also demonstrate the usefulness of newtype and how it can trivially make code more type safe, as well as providing more descriptive type signatures.

Level 3

Our application is starting to grow we should add another layer of assurance by writing some tests.

We will cover:

  • How to write a test-suite in the cabal file.
  • Usage of the hspec library as our test runner and how to feed it our application.
  • We will also write some tests using the hspec-wai package to give us some basic confidence in our error handling.

Level 4

This covers adding a database to our application.

  • We use SQLite because it requires the least amount of setup on the host machine.
  • All of the SQL is provided.

We will have the beginnings of some configuration in our application, but we will simply hardcode this for the time being as we will have a better solution in the next level.

We try to emphasise the distinction between data to be used externally in the Database vs the data we deal with internally in the application through the construction of our DBComment type.

The sqlite-simple-errors package is used to run our queries so that we have our errors as values, which is what we are doing in the rest of the application.

Again there will be a lot of documentation diving for this part as people will need to find the functions that will be used to run the queries against the database.

This level might be a bit hard to navigate as there are a bunch of files to walk through.

The steps for this level:

  1. src/FirstApp/DB/Types.hs
  2. src/FirstApp/Types.hs
  3. src/FirstApp/DB.hs
  4. src/FirstApp/Main.hs
  • Call out the encoding instances & the automatic deriving of the ToJSON instances

Level 5

We construct a proper method of handling our configuration.

This is a complex level due to having to handle the two configuration datatypes, plus the monoid instance. Additionally the configuration file is a JSON file that we manually extract information from using decoding functions from the aeson package. There will be documentation diving and possibly tricky functions involved.

I think it is important to not let people become hung up on the Monoid instance (it is partially completed already) additionally care needs to be taken that searching for the functions they need from the aeson library isn't too painful. Give hints or just tell them which functions.

The optparse-applicative library is used to handle the command line parsing but the students do not have to implement it themselves. It's it a gnarly library despite its usefullness, so it's there for people to look at and refer back to. But that's about it.

Exceptions will be discussed when working on the 'readObject' function to load the file into a JSON Value.

Level 6

This is "The ReaderT" level.

Students will be required to copy their completed versions of functions from previous levels that will then break in this level and need to be refactored. The bulk of the work will most likely be in the DB module as the DB functions no longer require the DB connection to be passed in manually.

Also there are functions in the FirstApp/Main module that will need to be updated to handle the new shenanigans.

Level 7

This is the "ExceptT" level.

Students go back to AppM module to see how the new transformer plugs into our stack, there are some functions to complete in here.

Then as per the previous level, the students have to copy over the completed functions from the previous level to see what breaks and what needs to be fixed. There will be a lot to do in the DB and FirstApp/Main modules.

General Notes - More to add.

  • structure repo
  • readme in each repo
  • monoid instance - rehash single/multiple number of possible instances. Don't let people hang too long on this point.
  • how to find the documentation for the Header / ContentType
  • more instruction that lead people to hackage documentation for Text/ByteString etc
  • mention that import lists may need to be updated for the new types
  • some editors will need to jump in and out of the different levels (close, cd, re-open)
  • Mention that it's fine to use case statements for Either handling, we make it okay at the end.

IMPORTANT!

  • Stephen Diehl - What I Wish I Knew Learning Haskell
  • Ask students if they would prefer access to a prepared VM with the code & an editor or two.