Skip to content

Instantly share code, notes, and snippets.

@lseppala
Created January 20, 2016 01:35
Show Gist options
  • Save lseppala/138f0c26171093fc56d6 to your computer and use it in GitHub Desktop.
Save lseppala/138f0c26171093fc56d6 to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
module NestedVL where
import Control.Monad.Free.VanLaarhovenE
data Logging m = Logging
{ logMsgF :: String -> m () }
logMsg :: HasEffect effects Logging
=> String
-> Free effects ()
logMsg s = liftF (`logMsgF` s)
data Nested m = Nested
{ nodeF :: m ()
, branchF
:: forall effects. HasEffect effects Nested
=> Free effects () -> m ()
}
node :: HasEffect effects Nested
=> Free effects ()
node = liftF (\eff -> nodeF eff)
branch :: HasEffect effects Nested
=> Free effects ()
-> Free effects ()
branch f = liftF (`branchF` f)
program :: ( HasEffect effects Nested
, HasEffect effects Logging )
=> Free effects ()
program =
branch $ do
logMsg "Inner branch"
node
branch $ node
interpretIO :: Effects effects IO -> Nested IO
interpretIO fx = Nested
{ nodeF = putStrLn "node"
, branchF = \f -> do
putStrLn "branch"
-- Need to evaluate sub expression
-- It should be something of the form
{-_ `iterM` f -}
-- My best guess was
{-nestEffect (interpretIO fx) fx `iterM` f-}
}
nestEffect :: Nested m -> Effects effects m -> Effects (Nested ': effects) m
nestEffect m fx = m .:. fx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment