{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE Safe #-}
module Control.Eff.Operational.Example where
import Control.Eff.Operational
import Control.Eff
import Control.Eff.Writer.Lazy
import Control.Eff.State.Lazy
data Jail a where
Print :: String -> Jail ()
Scan :: Jail String
prog :: Member (Program Jail) r => Eff r ()
prog = do
singleton $ Print "getting input..."
str <- singleton Scan
singleton $ Print "ok"
singleton $ Print ("the input is " ++ str)
adventIO :: Lifted IO r => Jail a -> Eff r a
adventIO (Print a) = lift $ putStrLn a
adventIO Scan = lift getLine
adventPure :: [ Writer String, State [String] ] <:: r => Jail a -> Eff r a
adventPure (Print a) = tell (a ++ "\n")
adventPure Scan = do
x <- get
case x of
[] -> return []
y:ys -> put ys >> return y