Created
April 28, 2017 13:16
-
-
Save Lazersmoke/d49ea7f7d715ac5d51d0b15afb229cc3 to your computer and use it in GitHub Desktop.
Forking Freer Monads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fork q where | |
type RuntimeConstraint q x :: Constraint | |
fork :: RuntimeConstraint q r => Eff (q ': r) a -> q (Eff r a) | |
data MyEffect a where | |
ForkMyEffect :: Member IO r => Eff (MyEffect ': r) a -> MyEffect (Eff r a) | |
Say :: MyEffect () | |
instance Fork MyEffect where | |
type RuntimeConstraint MyEffect x = Member IO x | |
fork = send . ForkMyEffect | |
runMyEffect :: Member IO r => IORef String -> Eff (MyEffect ': r) a -> Eff r a | |
runMyEffect _ (Pure x) = x | |
runMyEffect s (Eff u q) = case u of | |
Inject (ForkMyEffect e) -> runMyEffect s (runTCQ q (runMyEffect s e)) | |
Inject Say -> do | |
send (readIORef s >>= putStrLn) | |
runTCQ q () | |
Weaken otherEffects -> Eff otherEffects (Singleton (\x -> runMyEffect s (runTCQ q x))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment