Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
import Control.Monad.State
import Control.Applicative
data Foo = Foo0
| Foo1 Char
| Foo2 Bool Char
| Foo3 Char Bool Char
deriving Show
type Env a = State (String, [Bool]) a
class InEnv a where
envGet :: Int -> Env a
instance InEnv Char where
envGet i = do
(s, _) <- get
return $! s !! i
instance InEnv Bool where
envGet i = do
(_, b) <- get
return $! b !! i
cid :: Env Char
cid = envGet 1
bid :: Env Bool
bid = envGet 2
env :: (String, [Bool])
env = ("xy", map (==1) [0,0,1])
runEnv :: Env a -> a
runEnv f = evalState f env
test0 :: Foo
test0 = Foo0
test1 :: Foo
test1 = runEnv $ Foo1 <$> cid
test2 :: Foo
test2 = runEnv $ Foo2 <$> bid <*> cid
test3 :: Foo
test3 = runEnv $ Foo3 <$> cid <*> bid <*> cid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.