moo-nad-0.1.0.1: moo-nad.cabal
cabal-version: 3.0
name: moo-nad
version: 0.1.0.1
synopsis: Invocation helpers for the ReaderT-record-of-functions style.
description:
Using a record-of-functions as the environment of some
reader-like monad is a common way of structuring Haskell
applications, somewhat resembling dependency injection in OOP.
We often want our program logic to be polymorphic over both the
concrete monad and the environment. One common solution is to
abstract the monad using @MonadReader@, and abstract the environment
using @HasX@-style typeclasses.
One minor annoyance though is that invoking the function in the
environment is often a bit cumbersome: you have to ask
the environment for the function, and then lift the result of
the function back into the reader-like monad.
This library supports a special twist on @ReaderT@-record-of-functions
style: instead of depending only on typeclasses for abstraction,
we also use a module signature. This comes with different tradeoffs.
One benefit is that we support a simpler way of invoking functions from the
environment, using a helper that takes care of both asking the environment
and lifting function results, and which works uniformly for functions of any
arity.
license: BSD-3-Clause
license-file: LICENSE
author: Daniel Diaz Carrete
maintainer: diaz_carrete@yahoo.com
extra-source-files: CHANGELOG.md
common common
build-depends: base ^>= 4.15.0.0,
mtl ^>= 2.2,
dep-t ^>= 0.4.4
default-language: Haskell2010
-- Indefinite library which provides an invocation helper over some abstract
-- readerlike monad which carries a record-of-functions.
library
import: common
signatures: Moo
exposed-modules: Moo.Prelude
build-depends:
hs-source-dirs: lib
-- Example indefinite program logic.
library example-logic-that-logs
import: common
-- The Moo signature is enriched locally through signature merging.
signatures: Moo
exposed-modules: LogicThatLogs
build-depends:
moo-nad
hs-source-dirs: lib-example-logic-that-logs
-- Example library that implements the Moo signature.
library example-impl
import: common
exposed-modules: Moo
-- Notice that we don't depend explicitly on the Moo signature.
build-depends:
transformers ^>= 0.5
hs-source-dirs: lib-example-impl
-- The tests put together the moo-nad library, the example indefinite package
-- with the program logic, and the sublibrary carrying the implementation.
test-suite tests
import: common
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: tests.hs
build-depends:
tasty ^>= 1.3.1,
tasty-hunit ^>= 0.10.0.2,
example-logic-that-logs,
example-impl