mirror of
https://github.com/qfpl/applied-fp-course.git
synced 2024-11-26 14:43:53 +03:00
Add mention of fromIntegral
function.
Per #28 , added some wording for the `fromIntegral` function. Removed the 'aside' for `ghcid` as this was causing more problems than it was solving. Too many install / usage dramas. Added a snippet for loading a repl with test libraries and packages loaded. Because I had completely forgotten how to do that.
This commit is contained in:
parent
b43afca171
commit
554bdc1e08
@ -28,54 +28,18 @@ For a stack environment:
|
||||
$ stack build --test
|
||||
```
|
||||
|
||||
To load the tests in the REPL:
|
||||
|
||||
```shell
|
||||
# Cabal
|
||||
$ cabal repl level04-tests
|
||||
|
||||
# Stack
|
||||
$ stack ghci level04:level04-tests
|
||||
```
|
||||
|
||||
Start in ``tests/Test.hs``.
|
||||
|
||||
[HSpec]: (http://hspec.github.io/)
|
||||
[hspec-wai]: (https://hackage.haskell.org/package/hspec-wai)
|
||||
[doctest]: (https://hackage.haskell.org/package/doctest)
|
||||
|
||||
#### Aside: Tool Introduction - ghcid
|
||||
|
||||
[ghcid]: (https://github.com/ndmitchell/ghcid)
|
||||
|
||||
Additionally we'd like to introduce a command line tool that you may find useful
|
||||
for Haskell development; [ghcid]. This is a very lightweight tool that works for
|
||||
any project with a functioning cabal setup.
|
||||
|
||||
If you would like to use it, consult its documentation for how to install it,
|
||||
and then in an spare open terminal window, navigate to the root of the Haskell
|
||||
project and run ``$ ghcid``.
|
||||
|
||||
It will then attempt to build your project, if errors are found they will be
|
||||
displayed. But more importantly you can go back to editing files in the project
|
||||
and ``ghcid`` will refresh in the background. Providing you with new error
|
||||
messages or ``All Good`` if it cannot find any errors.
|
||||
|
||||
``ghcid`` provides extremely fast feedback, allowing for a nice development
|
||||
process with constant feedback about your changes. It is very useful in tandem
|
||||
with type holes. Give it a try!
|
||||
|
||||
``ghcid`` can also help out when you're writing your tests. Since normally the
|
||||
source and other packages that are listed in a `test-suite` configuration
|
||||
section in the Cabal file are not loaded. You can manually tell ``ghcid`` to
|
||||
load and examine these files with the following command:
|
||||
|
||||
```bash
|
||||
$ ghcid -c "cabal repl level03"
|
||||
|
||||
# Or for using ghcid to check your tests
|
||||
$ ghcid -c "cabal repl level03-tests"
|
||||
|
||||
# A note for sandboxed ghcid, you may need to provide an
|
||||
# explicit path to the binary:
|
||||
$ .cabal-sandbox/bin/ghcid -c "cabal repl level03-tests"
|
||||
```
|
||||
|
||||
It should work with ``stack`` as well:
|
||||
```bash
|
||||
$ ghcid -c "stack repl level03-tests"
|
||||
```
|
||||
|
||||
Please read the ``ghcid``documentation for installation and usage
|
||||
instructions. The [FAQ](https://github.com/ndmitchell/ghcid#faq) provides
|
||||
some useful tips.
|
@ -150,6 +150,8 @@ renderContentType JSON = "application/json"
|
||||
-- function in order to get the value out.
|
||||
--
|
||||
newtype Port = Port
|
||||
-- You will notice we're using ``Word16`` as our type for the ``Port`` value.
|
||||
-- This is because a valid port number can only be a 16bit unsigned integer.
|
||||
{ getPort :: Word16 }
|
||||
deriving (Eq, Show)
|
||||
|
||||
@ -157,7 +159,7 @@ newtype DBFilePath = DBFilePath
|
||||
{ getDBFilePath :: FilePath }
|
||||
deriving (Eq, Show)
|
||||
|
||||
-- The ``Conf`` type will need:
|
||||
-- Add some fields to the ``Conf`` type:
|
||||
-- - A customisable port number: ``Port``
|
||||
-- - A filepath for our SQLite database: ``DBFilePath``
|
||||
data Conf = Conf
|
||||
@ -166,6 +168,12 @@ data Conf = Conf
|
||||
-- values from being used in our application. However Wai is not so stringent.
|
||||
-- To accommodate this and make our lives a bit easier, we will write this
|
||||
-- helper function to take ``Conf`` value and convert it to an ``Int``.
|
||||
--
|
||||
-- We'll need to use a function called; ``fromIntegral``, to convert our
|
||||
-- ``Word16`` to an ``Int``. The type of this function is:
|
||||
--
|
||||
-- fromIntegral :: (Num b, Integral a) => a -> b
|
||||
--
|
||||
confPortToWai
|
||||
:: Conf
|
||||
-> Int
|
||||
|
Loading…
Reference in New Issue
Block a user