prospect: Explore continuations with trepidation

[ bsd3, control, library ] [ Propose Tags ]

Please see the README on GitHub at

[Skip to Readme]




Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


  • No Candidates
Versions [RSS]
Change log
Dependencies base (>=4.7 && <5), deepseq, free, kan-extensions, mtl, transformers [details]
License BSD-3-Clause
Copyright 2018 Sandy Maguire
Author Sandy Maguire
Category Control
Home page
Bug tracker
Source repo head: git clone
Uploaded by isovector at 2018-07-10T19:54:55Z
Distributions LTSHaskell:, NixOS:, Stackage:
Reverse Dependencies 1 direct, 0 indirect [details]
Downloads 1060 total (13 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2018-07-10 [all 1 reports]

Readme for prospect-

[back to package description]


Build Status | Hackage


It is absolutely necessary, for the peace and safety of mankind, that some of earth's dark, dead corners and unplumbed depths be let alone; lest sleeping abnormalities wake to resurgent life, and blasphemously surviving nightmares squirm and splash out of their black lairs to newer and wider conquests.

H.P. Lovecraft


prospect is a library that provides primitives for exploring functions, and by extension, monads. As such, it allows for a best-attempt static analysis of free monads. Such power, however, does not come for free; using prospect is an implicit promise with the Eldrich horrors that you'll tread lightly. Feckless wanderers into these depths will be rewarded with naught but terror, madness, and runtime crashes.


The library provides a function, prospect :: Free f a -> (Maybe a, [f ()]), which can probe the depths of a free monad, finding as many f constructors as it can before the monad branches dynamically.

Be careful when inspecting the f ()s, if any of them depend on variables bound in the monad, they will leak exceptions when you are least expecting them. It's a good idea to run your f ()s through ensure :: Alternative m => a -> m a after you've scrutinized their constructors.


prospect can be used to perform a best-effort static analysis of a free monad:

data Pattern a
  = Cont (Bool -> a)
  | Action Int a
  deriving (Functor, Generic1)

cont :: MonadFree Pattern m => m Bool
cont = liftF $ Cont id

action :: MonadFree Pattern m => Int -> m ()
action i = liftF $ Action i ()

success :: (Maybe String, [Pattern ()]
success = prospect $ do
  a <- cont
  action 1
  pure "success"
-- success = (Just "success", [Cont (const ()), Action 1 ()])

failure :: (Maybe String, [Pattern ()]
failure = prospect $ do
  a <- cont
  action 1
  if a  -- static analysis ends here, as it would require branching on the
        -- result of a monadic action
    then action 2
    else action 3
  action 4
  pure "failure"
-- failure = (Nothing, [Cont (const ()), Action 1 ()])

In these examples, we can continue analyzing a Free Pattern monad until the result of its Cont continuation is forced.