10 Jul 01:52 2014

## extensible-transformers

Ben Foppa <benjamin.foppa <at> gmail.com>

2014-07-09 23:52:17 GMT

2014-07-09 23:52:17 GMT

Hi cafe, I whipped up extensible-transformers (

https://github.com/RobotGymnast/extensible-transformers) this afternoon. The idea is to make Monad transformer code more like extensible-effects code (http://hackage.haskell.org/package/extensible-effects). Here's a sample:

https://github.com/RobotGymnast/extensible-transformers) this afternoon. The idea is to make Monad transformer code more like extensible-effects code (http://hackage.haskell.org/package/extensible-effects). Here's a sample:

{-# LANGUAGE FlexibleContexts #-}

module Main(main) where

import Control.Monad.Trans.Flexible

import Control.Monad.Trans.List

import Control.Monad.Trans.State.Strict

-- A flexible transformer stack built from existing transformers using `liftT`.

bar :: (In (StateT Int) t, In ListT t) => t ()

bar = do

n <- liftT get

liftT $ ListT $ return $ replicate n ()

-- A flexible transformer stack built from existing transformers using `liftT`.

baz :: In (StateT Int) t => t ()

baz = do

liftT $ state $ \i -> ((), i + (1 :: Int))

-- A flexible transformer monad stack composed of two other flexible

-- transformer monad stacks.

foo :: (In (StateT Int) t, In ListT t) => t ()

foo = do

bar

baz

main :: IO ()

main = do

evalStateT (runListT foo) (1 :: Int) >>= putStrLn . show

runListT (evalStateT foo (2 :: Int)) >>= putStrLn . show

Any feedback on this? Does such a package already exist?

Ben

_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe <at> haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe