Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fumieval/monad-skeleton
Operational monad library
https://github.com/fumieval/monad-skeleton
haskell monads
Last synced: about 2 months ago
JSON representation
Operational monad library
- Host: GitHub
- URL: https://github.com/fumieval/monad-skeleton
- Owner: fumieval
- License: bsd-3-clause
- Created: 2015-03-27T07:07:21.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2021-11-30T08:13:45.000Z (about 3 years ago)
- Last Synced: 2024-10-11T21:43:30.233Z (3 months ago)
- Topics: haskell, monads
- Language: Haskell
- Homepage:
- Size: 43 KB
- Stars: 30
- Watchers: 8
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
monad-skeleton
======================[![Build Status](https://travis-ci.org/fumieval/monad-skeleton.svg?branch=master)](https://travis-ci.org/fumieval/monad-skeleton)
[![Hackage](https://img.shields.io/hackage/v/monad-skeleton.svg)](https://hackage.haskell.org/package/monad-skeleton)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)`:```haskell
data MonadView t m x where
Return :: a -> MonadView t m a
(:>>=) :: !(t a) -> (a -> m b) -> MonadView t m bboned :: MonadView t (Skeleton t) a -> Skeleton t a
debone :: Skeleton t a -> MonadView t (Skeleton t) a
```GADTs are handy to define instructions:
```haskell
data Interaction x where
Get :: Interaction String
Put :: String -> Interaction ()echo :: Skeleton Interaction ()
echo = bone Get >>= bone . Put
```Use `debone` to interpret a computation.
```haskell
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
```