GithubHelp home page GithubHelp logo

beeleebow / cis194-exercises Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stacktracehq/cis194-exercises

0.0 1.0 0.0 318 KB

A test suite for the homework exercises from Brent Yorgey's CIS 194 lecture series on Haskell

License: BSD 3-Clause "New" or "Revised" License

Haskell 97.46% Nix 1.82% Shell 0.72%

cis194-exercises's Introduction

In-house Training Based on CIS 194 Haskell Course

What is this?

We decided we wanted to ramp up the team's functional programming skills. To this end, we committed to working through Brent Yorgey's CIS 194 lecture series on Haskell. This is a 12 week course and there are homework assignments for each week.

Our goal is to work through a week of the course's content every Friday afternoon. Our first session will be on Friday the 20th of July, 2018.

Jump into the #fp channel in the Stacktrace slack to chat about the course, or any FP concepts in general.

How to work with this Repository

Setup

Option 1 (recommended)

  1. Install the Nix package manager

  2. Run the following

$ nix-shell --command 'cabal configure --enable-tests && cabal test'
  1. To run ghci
$ nix-shell --command ghci

From now on you can type nix-shell and be put into a bash shell which has ghc, ghci, cabal, ghcid, hlint, and hindent. For more info on using Nix ask in #dotfiles.

Option 2

  1. Install the Haskell Platform. This includes the ghc compiler, ghci repl, and cabal build tool.

  2. Run the following

$ cabal configure
$ cabal install cabal-install
$ cabal install --only-dependencies --enable-tests
$ cabal configure --enable-tests
$ cabal test
  1. To run ghci
$ ghci

Using ghci

You'll be spending a lot of time in ghci, which is a Read, Eval, Print, Loop (aka 'repl'). Once you enter ghci you can run commands, which are prefixed with ':'. Entering :help will print a list of available commands.

The most helpful of these are likely to be :info and :type.

:info or :i for short will tell you everything GHCI can about an expression.

 > :i Maybe
data Maybe a = Nothing | Just a         -- Defined in ‘GHC.Base’
instance Applicative Maybe -- Defined in ‘GHC.Base’
... MORE

 > :i (+)
class Num a where
  (+) :: a -> a -> a
  ...
        -- Defined in ‘GHC.Num’
infixl 6 +

:type or :t for short will tell you the type of an expression.

 > :t Just
Just :: a -> Maybe a

 > :t (+)
(+) :: Num a => a -> a -> a

Homework Exercises

Each week we'll be adding a set of hspec specs in a ./test/Week<N>/ directory. We'll also add some files in ./src/Week<N>/ to serve as a starting point for your implementations. To run only the tests for a given week you can use GHCI. Below is an example of running only the credit card tests for week one.

$ ghci test/Week01/CreditCardValidatorSpec.hs
GHCi, version 8.2.2: http://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /Users/bradparker/code/cosmos/training/CIS194/.ghci
Ok, two modules loaded.
 > hspec spec

CreditCardValidator
  toDigits
    converts positive Integers to a list of digits FAILED [1]
  toDigitsRev
    does what toDigits does in reverse FAILED [2]
  doubleEveryOther
    doubles every second digit starting from the second last FAILED [3]
  sumDigits
    sums the sum of the digits of all numbers in a list FAILED [4]
  validate
    indicates whether an Integer could be a valid credit card number FAILED [5]

Failures:
... error details and more!

You can also run dev/watch to get a file-watching test-re-running setup going with the help of GHCID.

To run only the tests for a given spec file using the watch script (defaults to all specs):

$ dev/watch test/Week01/CreditCardValidatorSpec.hs

cis194-exercises's People

Contributors

bradparker avatar

Watchers

Brad Bow avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.