Running Tests

Execute the following command to run the tests:

1
stack test

If you get an error message like this...

1
No .cabal file found in directory

You are probably running an old stack version and need to upgrade it.

Otherwise, if you get an error message like this...

1
2
No compiler found, expected minor version match with...
Try running "stack setup" to install the correct GHC...

Just do as it says and it will download and install the correct compiler version:

1
stack setup

Solving the exercise

A solution to an exercise is a Haskell module. The module's name is defined in an import statement in the test suite, usually at the beginning:

1
2
3
4
5
6
7
import Test.Hspec        (Spec, describe, it, shouldBe)
import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith)

import ModuleName (someFunc)

main :: IO ()
main ...

In this example, the test file imports, in line 4, a module named ModuleName, that exports a function named someFunc. This means you have to create a file named ModuleName.hs that would be something like this:

1
2
3
4
module ModuleName (someFunc) where

someFunc :: ...
someFunc ...

You'll a find a file with this name already in place in src/, which you can use as a starting point for your solution.

Just keep in mind that this stub is there just for you to get started. Feel free to change it completely if you think it is the right thing to do.

Using packages

If you want to use some packages to write a more elegant solution, just add the packages to your solution's dependencies in package.yaml:

1
2
3
4
5
6
library:
  exposed-modules: ModuleName
  source-dirs: src
  dependencies:
    - foo
    - bar

Running GHCi

If you want to play with your solution in GHCi, just run the command:

1
stack ghci

HLint (optional)

It's highly recommended that you run hlint on your solution to see if it catches something you are missing:

1
hlint ModuleName.hs

You don't have to accept all the suggestions given by hlint, but usually they will help you learn how to write beautiful, idiomatic Haskell code.


Help us explain this better! File a GitHub issue at https://github.com/exercism/haskell/issues if you have suggestions, or submit a patch with improvements to the https://github.com/exercism/haskell/blob/master/docs/TESTS.md file.