monad-skeleton: Monads of program skeleta

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

Fast operational monad library


[Skip to Readme]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0, 0.1, 0.1.1, 0.1.2, 0.1.2.1, 0.1.2.2, 0.1.3, 0.1.3.1, 0.1.3.2, 0.1.4, 0.1.5, 0.2
Change log CHANGELOG.md
Dependencies base (>=4.9 && <4.17) [details]
License BSD-3-Clause
Copyright Copyright (c) 2021 Fumiaki Kinoshita
Author Fumiaki Kinoshita
Maintainer Fumiaki Kinoshita <fumiexcel@gmail.com>
Category Control, Monads
Home page https://github.com/fumieval/monad-skeleton
Bug tracker http://github.com/fumieval/monad-skeleton/issues
Source repo head: git clone https://github.com/fumieval/monad-skeleton.git
Uploaded by FumiakiKinoshita at 2021-11-30T08:13:32Z
Distributions LTSHaskell:0.2, NixOS:0.2, Stackage:0.2
Downloads 9239 total (37 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for monad-skeleton-0.2

[back to package description]

monad-skeleton

Build Status Hackage

This package provides Skeleton, an operational monad (i.e. free monad that does not require the Functor implementation). The internal encoding gives O(1) bind and monadic reflection.

Skeleton promotes unit instructions to a monad. It is isomorphic to MonadView (Skeleton t):

data MonadView t m x where
  Return :: a -> MonadView t m a
  (:>>=) :: !(t a) -> (a -> m b) -> MonadView t m b

boned :: MonadView t (Skeleton t) a -> Skeleton t a
debone :: Skeleton t a -> MonadView t (Skeleton t) a

GADTs are handy to define instructions:

data Interaction x where
  Get :: Interaction String
  Put :: String -> Interaction ()

echo :: Skeleton Interaction ()
echo = bone Get >>= bone . Put

Use debone to interpret a computation.

interpret :: Skeleton Interaction a -> IO a
interpret m = case debone m of
  Return a -> return a
  Get :>>= k -> getLine >>= interpret . k
  Put s :>>= k -> putStrLn s >>= interpret . k