1
1
mirror of https://github.com/qfpl/applied-fp-course.git synced 2024-11-27 01:23:00 +03:00

Wording Updates

Removed a silly usage of `either` and fixed up a typo and some other
phrasing changes.
This commit is contained in:
Sean Chalmers 2017-08-22 09:14:19 +10:00
parent 3a6ebcb01d
commit c37183cdf2
3 changed files with 5 additions and 10 deletions

View File

@ -9,13 +9,7 @@ import Data.Text (Text)
import FirstApp.Conf (Conf)
import FirstApp.DB (FirstAppDB)
-- One motivation for using ReaderT is that there exists some information in
-- your application that is used almost everywhere and it is tiresome to have to
-- weave it through everywhere. We also don't allow "global variables" as they
-- are error prone, fragile, and prevent you from properly being able to reason
-- about the operation of your program.
--
-- a ReaderT is a function from some 'r' to some 'm a' : (r -> m a). Where by
-- a ReaderT is a function from some 'r' to some 'm a' : (r -> m a). Whereby
-- the 'r' is accessible to all functions that run in the context of that 'm'.
--
-- This means that if you use the 'r' everywhere or simply enough throughout
@ -48,7 +42,7 @@ newtype AppM a = AppM
-- but the name differences alone make the confusion a little less likely.
{ unAppM :: ReaderT Env IO a }
-- Because we're using a newtype, all of the instance definitions for ReaderT
-- would normally no apply. However, because we've done nothing but create a
-- would normally not apply. However, because we've done nothing but create a
-- convenience wrapper for our ReaderT, there is an extension for Haskell that
-- allows it to simply extend all the existing instances to work without AppM.
-- Add the GeneralizedNewtypeDeriving pragma to the top of the file and these
@ -85,4 +79,3 @@ runAppM
-> IO a
runAppM env appM =
runReaderT (unAppM appM) env

View File

@ -14,6 +14,7 @@ import Control.Monad.Reader (asks)
import Network.Wai
import Network.Wai.Handler.Warp (run)
import Data.Bifunctor (first)
import Data.Either (Either (..), either)
import Data.Text (Text)
@ -73,7 +74,7 @@ prepareAppReqs = do
-- This just makes it a bit easier to take our individual initialisation
-- functions and ensure that they both conform to the StartUpError type
-- that we want them too.
fmap ( either (Left . e) Right )
fmap (first e)
initConf = toStartUpErr ConfErr
-- Prepare the configgening

View File

@ -50,6 +50,7 @@ main = do
-- Run the tests with a DB topic flush between each spec
hspec . with ( flushTopic >> app' ) $ do
-- Save us a bit of repetition
let pOST = post ( "/" <> testTopic <> "/add" )
-- AddRq Spec