Comments (2)
Hi Sjoerd,
Thanks for the input. I have uploaded to Hackage a new version including induce.
I cooked an example based on Swierstra calculator:
import Control.Monad.Free
import Control.Monad.State
data CalcF a = Incr Int a
| Recall (Int -> a)
| Clear a
deriving Functor
type Calc a = Free CalcF a
clear :: Calc ()
incr :: Int -> Calc ()
clear = Impure $ Clear (Pure ())
incr i = Impure $ Incr i (Pure ())
recall = Impure (Recall Pure)
runCalc :: Calc a -> Int
runCalc = (`execState` 0) . induce f where
f (Incr i r) = modify (+i) >> return r
f (Clear r) = put 0 >> return r
f (Recall k) = get >>= \i -> return (k i)
Do you have any other examples in mind?
from control-monad-free.
I like your example a lot!
This was the Agda code I wanted to implement in Haskell:
http://personal.cis.strath.ac.uk/~ng/MonadicIR.agda
It now becomes:
class Reflective f where
reflect :: Monad m => f i o -> m i -> m o
decode :: (Reflective f, Functor (f i), Monad m) => Free (f i) o -> m i -> m o
decode = runReaderT . induce (ReaderT . reflect)
Pretty nice, but totally useless, as it all has to be done at type level to be of any use for induction recursion.
from control-monad-free.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from control-monad-free.