freer-simple: A friendly effect system for Haskell.

[ bsd3, control, library, program ] [ Propose Tags ]

An implementation of an effect system for Haskell (a fork of freer-effects), which is based on the work of Oleg Kiselyov et al.:

The key features are:

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

  • Reimplementations of several common Haskell monad transformers as effects.

  • Core components for defining your own Effects.

[Skip to Readme]


Maintainer's Corner

For package maintainers and hackage trustees


  • No Candidates
Versions [RSS],,,,,,,
Change log
Dependencies base (>=4.9 && <5), freer-simple, natural-transformation (>=0.2), template-haskell (>=2.11 && <2.19), transformers-base [details]
License BSD-3-Clause
Copyright 2016 Allele Dev; 2017 Ixperta Solutions s.r.o.; 2017 Alexis King
Author Allele Dev, Ixcom Core Team, Alexis King, and other contributors
Maintainer Alexis King <>
Category Control
Home page
Bug tracker
Source repo head: git clone
Uploaded by lexi_lambda at 2022-01-07T20:29:11Z
Distributions LTSHaskell:, NixOS:, Stackage:
Executables freer-simple-examples
Downloads 7502 total (187 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2022-01-07 [all 1 reports]

Readme for freer-simple-

[back to package description]

freer-simple — a friendly effect system for Haskell Build Status Hackage

The freer-simple library is an implementation of an extensible effect system for Haskell, a general-purpose way of tracking effects at the type level and handling them in different ways. The concept of an “effect” is very general: it encompasses the things most people consider side-effects, like generating random values, interacting with the file system, and mutating state, but it also includes things like access to an immutable global environment and exception handling.

The key features of freer-simple are:

  • An efficient effect system for Haskell as a library.

  • Implementations for several common Haskell monads as effects, including Reader, Writer, State, Error, and others.

  • A combinator language for defining your own effects, designed to make simple, common use cases easy to read and write.

For more details, see the package documentation on Hackage.

Code example

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}

import qualified Prelude
import qualified System.Exit

import Prelude hiding (putStrLn, getLine)

import Control.Monad.Freer
import Control.Monad.Freer.TH
import Control.Monad.Freer.Error
import Control.Monad.Freer.State
import Control.Monad.Freer.Writer

                               -- Effect Model --
data Console r where
  PutStrLn    :: String -> Console ()
  GetLine     :: Console String
  ExitSuccess :: Console ()
makeEffect ''Console

                          -- Effectful Interpreter --
runConsole :: Eff '[Console, IO] a -> IO a
runConsole = runM . interpretM (\case
  PutStrLn msg -> Prelude.putStrLn msg
  GetLine -> Prelude.getLine
  ExitSuccess -> System.Exit.exitSuccess)

                             -- Pure Interpreter --
runConsolePure :: [String] -> Eff '[Console] w -> [String]
runConsolePure inputs req = snd . fst $
    run (runWriter (runState inputs (runError (reinterpret3 go req))))
    go :: Console v -> Eff '[Error (), State [String], Writer [String]] v
    go (PutStrLn msg) = tell [msg]
    go GetLine = get >>= \case
      [] -> error "not enough lines"
      (x:xs) -> put xs >> pure x
    go ExitSuccess = throwError ()


The freer-simple package began as a fork of freer-effects by Ixperta Solutions, which in turn is a fork of freer by Allele Dev. All implementations are based on the paper and reference implementation by Oleg Kiselyov.