freer: Implementation of the Freer Monad

[ bsd3, control, library, program ] [ Propose Tags ] [ Report a vulnerability ]

Freer is an implementation of "Freer Monads, More Extensible Effects"

The key features of Freer are:

  • An efficient effect system for Haskell - as a library!

  • Implementations for several common Haskell monad instances:

  • Core components for defining your own Effects


[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.2.2.1, 0.2.2.2, 0.2.2.3, 0.2.2.4, 0.2.2.5, 0.2.2.6, 0.2.3.0, 0.2.4.0, 0.2.4.1
Change log changelog.md
Dependencies base (>=4.8 && <4.9), freer [details]
Tested with ghc ==7.10.2
License BSD-3-Clause
Copyright Allele Dev 2016
Author Allele Dev
Maintainer allele.dev@gmail.com
Revised Revision 1 made by HerbertValerioRiedel at 2016-11-25T08:34:45Z
Category Control
Home page https://gitlab.com/queertypes/freer
Bug tracker https://gitlab.com/queertypes/freer/issues
Source repo head: git clone git clone https://gitlab.com/queertypes/freer.git
Uploaded by alcabrera at 2016-04-06T20:33:17Z
Distributions NixOS:0.2.4.1
Executables examples
Downloads 7484 total (19 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2016-04-06 [all 1 reports]

Readme for freer-0.2.2.5

[back to package description]

Freer: Extensible Effects with Freer Monads

Freer is an implementation of "Freer Monads, More Extensible Effects". Much of the implementation is a repackaging and cleaning up of the reference materials provided here.

Features

The key features of Freer are:

  • An efficient effect system for Haskell as a library
  • Implementations for several common Haskell monad instances:
    • Reader
    • Writer
    • State
    • StateRW: State in terms of Reader/Writer
    • Trace
    • Exception
  • Core components for defining your own Effects

Example: Teletype DSL

Here's what using Freer looks like:

{-# LANGUAGE GADTs #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
module Teletype where

import Control.Monad.Freer
import Control.Monad.Freer.Internal
import System.Exit hiding (ExitSuccess)

--------------------------------------------------------------------------------
                          -- Effect Model --
--------------------------------------------------------------------------------
data Teletype s where
  PutStrLn    :: String -> Teletype ()
  GetLine     :: Teletype String
  ExitSuccess :: Teletype ()

putStrLn' :: Member Teletype r => String -> Eff r ()
putStrLn' = send . PutStrLn

getLine'  :: Member Teletype r => Eff r String
getLine' = send GetLine

exitSuccess' :: Member Teletype r => Eff r ()
exitSuccess' = send ExitSuccess

--------------------------------------------------------------------------------
                     -- Effectful Interpreter --
--------------------------------------------------------------------------------
runTeletype :: Eff '[Teletype] w -> IO w
runTeletype (Val x) = return x
runTeletype (E u q) = case decomp u of
              Right (PutStrLn msg) -> putStrLn msg  >> runTeletype (qApp q ())
              Right GetLine        -> getLine      >>= \s -> runTeletype (qApp q s)
              Right ExitSuccess    -> exitSuccess
              Left  _              -> error "This cannot happen"

--------------------------------------------------------------------------------
                        -- Pure Interpreter --
--------------------------------------------------------------------------------
runTeletypePure :: [String] -> Eff '[Teletype] w -> [String]
runTeletypePure inputs req = reverse (go inputs req [])
  where go :: [String] -> Eff '[Teletype] w -> [String] -> [String]
        go _      (Val _) acc = acc
        go []     _       acc = acc
        go (x:xs) (E u q) acc = case decomp u of
          Right (PutStrLn msg) -> go (x:xs) (qApp q ()) (msg:acc)
          Right GetLine        -> go xs     (qApp q x) acc
          Right ExitSuccess    -> go xs     (Val ())   acc
          Left _               -> go xs     (Val ())   acc

Contributing

Contributions are welcome! Documentation, examples, code, and feedback - they all help.

Be sure to review the included code of conduct. This project adheres to the Contributor's Covenant. By participating in this project you agree to abide by its terms.

Developer Setup

The easiest way to start contributing is to install stack. stack can install GHC/Haskell for you, and automates common developer tasks.

The key commands are:

  • stack setup : install GHC
  • stack build
  • stack clean
  • stack haddock : builds documentation
  • stack test
  • stack bench
  • stack ghci : start a REPL instance

Licensing

This project is distrubted under a BSD3 license. See the included LICENSE file for more details.

Acknowledgements

This package would not be possible without the paper and the reference implementation. In particular:

There will be deviations from the source.