The monad-skeleton package

[Tags:bsd3, library]

Fast operational monad library


[Skip to Readme]

Properties

Versions 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
Dependencies base (==4.*) [details]
License BSD3
Copyright Copyright (c) 2017 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 repository head: git clone https://github.com/fumieval/monad-skeleton.git
Uploaded Thu Mar 16 07:26:49 UTC 2017 by FumiakiKinoshita
Distributions LTSHaskell:0.1.3.2, NixOS:0.1.3.2, Stackage:0.1.3.2, Tumbleweed:0.1.3.2
Downloads 965 total (59 in the last 30 days)
Votes
0 []
Status Docs available [build log]
Last success reported on 2017-03-16 [all 1 reports]

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Readme for monad-skeleton

Readme for monad-skeleton-0.1.3.2

monad-skeleton

Build Status Hackage

This package provides Skeleton, an operational monad. 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 :: Interacton 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