• Stars
    star
    106
  • Rank 325,871 (Top 7 %)
  • Language
    Haskell
  • License
    ISC License
  • Created about 7 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A small example of using mtl style to unit test effectful code

haskell-mtl-style-example

This project includes a small example of using the so-called “mtl style” to unit test effectful Haskell code in a completely pure, IO-free way. The program it tests is extremely simple, but it performs numerous side-effects, making it tricky to completely test without IO: it uses command-line arguments, reads a file, prints log messages, and uses the system clock to calculate its running time.

The code is divided into the following modules:

  • MTLStyleExample.Main

    This module implements the actual program logic. The logic is not especially complex, so this module is small compared to the rest of the code, but in a real program, it would likely dwarf the rest of the program in size.

    In addition to implementing the program logic, this module also contains the effectful transformer stack that implements the effects when running the program for “real”.

  • MTLStyleExample.Interfaces

    This module contains the mtl-style typeclasses that are used to decouple the effect interfaces used in the code from their implementations. It also includes implementations of some of the interfaces in IO, which are trivial by design—the real implementations must be trivial, or there is logic that is not under test coverage!

  • MTLStyleExample.MainSpec

    The unit tests for the logic defined in MTLStyleExample.Main. Note that all of the functionality of the program is tested in a completely pure way without needing to perform an effectful end-to-end or integration test.

  • MTLStyleExample.Test.Stubs

    This includes the “fake” test-time implementation of the interfaces defined in MTLStyleExample.Interfaces, and these implementations are used in MTLStyleExample.MainSpec. These attempt to implement the interfaces as faithfully as possible without needing to use an actual file system, the real system clock, or the real standard output.

    This code ends up actually being some of the most verbose in the entire project, but remember that each of these fake implementations only needs to be written once per effect, so even as the program logic grows, this module never needs to change.

For some additional information on one of the techniques used in this project (that is, using DefaultSignatures to make lifting instances derivable), see my blog post Lifts for free: making mtl typeclasses derivable.

More Repositories

1

hackett

WIP implementation of a Haskell-like Lisp in Racket
Racket
1,149
star
2

freer-simple

A friendly effect system for Haskell
Haskell
222
star
3

eff

🚧 a work in progress effect system for Haskell 🚧
Haskell
113
star
4

higher-rank

A small Haskell implementation of Complete and Easy Bidirectional Typechecking for Higher-Rank Polymorphism
Haskell
101
star
5

racket-r7rs

An implementation of R7RS in Racket
Racket
92
star
6

megaparsack

Racket parser combinators inspired by parsack and megaparsec
Racket
76
star
7

racket-collections

Generic collections API for Racket
Racket
52
star
8

blackboard

A (very) unfinished OpenType Math layout and rendering engine in Racket
Racket
51
star
9

threading

Threading macros for Racket
Racket
47
star
10

talks

Racket
42
star
11

functional

Functional interfaces and datatypes for Racket
Racket
42
star
12

monad-validate

A Haskell monad transformer library for data validation
Haskell
35
star
13

shattered-plans

Java
31
star
14

racket-commonmark

Fast, CommonMark-compliant Markdown parser written in Racket
Racket
31
star
15

heroku-buildpack-racket

a Heroku buildpack for deploying apps written in Racket
Shell
27
star
16

lexi-lambda.github.io

Racket
27
star
17

racket-mvar

An implementation of Haskell’s MVars in Racket
Racket
27
star
18

mini-ml

An experimental implementation of a tiny ML-like language using an embedded custom expander (WIP, currently just System F core language)
Racket
21
star
19

racket-higher-rank

Racket
21
star
20

envy

An environment variable manager for Racket applications
Racket
17
star
21

racket-curly-fn

A meta-language for adding Clojure-style shorthand function literals to arbitrary Racket languages.
Racket
16
star
22

racket-tulip

Racket
15
star
23

racket-alexis-collections

Deprecated. Use https://github.com/lexi-lambda/racket-collections instead.
Racket
12
star
24

libsol

A C runtime for the sol programming language.
C
11
star
25

racket-multimethod

Proof-of-concept, mostly safe multimethods in Racket
Racket
11
star
26

case-kw-lambda

Racket
11
star
27

racket-alexis-pvector

Deprecated. Use https://github.com/lexi-lambda/racket-pvector instead.
Racket
11
star
28

scripty

Distributable shell scripts with dependencies
Racket
10
star
29

racket-macro-exercises

Small macro challenges to help learn Racket’s macro system
Racket
9
star
30

lens-examples

A handful of small examples of parts of the Haskell `lens` package
Haskell
8
star
31

racket-2htdp-typed

A port of 2htdp to Typed Racket
Racket
8
star
32

learning-haskell

Racket
8
star
33

racket-pvector

Fast, immutable, persistent vectors for Racket
Racket
8
star
34

dotfiles

Racket
7
star
35

namespaced-transformer

Racket
6
star
36

racket-sample-heroku-app

a sample Racket application for deployment to Heroku
Racket
6
star
37

factorio-blueprints

Makefile
6
star
38

syntax-classes

Racket
5
star
39

SimpleJail

Simplistic Jail plugin for Bukkit
Java
5
star
40

clojure-fuzzy-urls

Clojure
5
star
41

struct-update

Racket
5
star
42

th-to-exp

Deprecated. Use Language.Haskell.TH.Syntax.Lift instead.
Haskell
4
star
43

aws-cloudformation-template

Racket
4
star
44

litpub

A small Medium clone in Racket designed for publishing stories
Racket
4
star
45

decontaminate

A Ruby DSL for extracting data from complicated XML documents
Ruby
3
star
46

alexis-collection-lens

Lens provider for Racket generic collections
Racket
3
star
47

SNESTile

A cross-platform SNES graphics editor.
Java
3
star
48

collections-lens

Lenses for Racket generic collections
Racket
3
star
49

racket-irc-client

Racket
3
star
50

racket-alexis

Various personal libraries and utilities for Racket
Racket
3
star
51

racket-match-plus

Racket
2
star
52

rackunit-spec

Racket
2
star
53

simple_split

dead simple A/B testing on Rails
Ruby
2
star
54

haskell-rolodex

Haskell
2
star
55

type-assertions

Runtime type assertions for testing
Haskell
1
star
56

monads-lecture

Haskell
1
star
57

racket-vector-struct

Racket
1
star
58

racket-semver

A Racket implementation of the semver specification
Racket
1
star
59

imgcap

Racket
1
star
60

incremental

Haskell
1
star
61

ut2k4-team-stats

A simple app that uses the data from the UT2k4 Stats server to track the performance of team duos
Racket
1
star
62

template-dom

A library for creating (V)DOM nodes using ES2015 tagged template strings
JavaScript
1
star