Coder Social home page Coder Social logo

haskell-readert's Introduction

Haskell ReaderT Application Architecture Example

This repository demonstrates how to use the ReaderT pattern to structure your Haskell code.

The goal is to have a body of code that tries to be minimal but also not too far away from production-reader at the same time. For example, I kept everything in a single library file, which is unlikely in production but helps with having the entire thing in front of you. On the other hand imports are qualified and I'm using Text instead of String, to satisfy typical production needs.

The example is heavily inspired by the documentation for RIO, particularly the point about

a perfect balance point in the composability/concreteness space

You might notice that I'm essentially reimplementing the environment type in my tests. The reason for this is that I expect a production environment to include many things which are irrelevant for more focused integration or even unit tests. In such cases you have two choices. You can share a single environment, at the cost of having to supply fake implementations for all the things you don't care about. Or you implement subsets of the environment, but then you need to reimplement some of the Has typeclasses and potentially other concerns, such as Katip logging in this example.

I'm sure there are more advanced solutions to this problem, but ReaderT is generally appreciated for not being too fancy, and as such I kept the repository simple as well.

Feel free to suggest changes through issues or pull requests!

Commands

  1. Generate project.nix if no Nix environment is available or Nix compilation failed.
  2. Run the main executable
  3. Run the tests
  4. Start ghcid for checking the executable
  5. Start ghcid for checking the tests
$ nix-shell --packages cabal2nix --run 'cabal2nix . > project.nix'
$ cabal v2-run exe:haskell-readert
$ cabal v2-run test:tests
$ ghcid --no-height-limit --clear --reverse --target=exe:haskell-readert
$ ghcid --no-height-limit --clear --reverse --target=test:tests

haskell-readert's People

Contributors

cidem avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

decentn2madness

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.