Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
>>>
:set -XTypeFamilies
>>>
:set -XMultiParamTypeClasses
>>>
:set -XFlexibleInstances
>>>
:set -XFlexibleContexts
>>>
:set -XRebindableSyntax
>>>
:set -XTypeApplications
>>>
import qualified Prelude
>>>
import Prelude hiding ((>>), (>>=), return)
>>>
import Control.Dsl
>>>
import Control.Dsl.State
>>>
import Control.Dsl.Yield
>>>
import Control.Dsl.Return
>>>
import Data.Void
>>>
:{
f = do Yield "foo" config <- Get @Bool when config $ do Yield "bar" return () return "baz" :}
>>>
:type f
f :: (Dsl (Yield [Char]) r (), Dsl (Return [Char]) r Void, Dsl Get r Bool) => r
>>>
f True :: [String]
["foo","bar","baz"]
>>>
:{
instance Dsl (Yield String) (IO ()) () where cpsApply (Yield a) = (Prelude.>>=) (putStrLn $ "Yield " ++ a) :}
>>>
:{
instance Dsl Get (IO ()) Bool where cpsApply Get f = (putStrLn "Get") Prelude.>> f False :}
>>>
:{
instance Dsl (Return String) (IO ()) Void where cpsApply (Return a) _ = putStrLn $ "Return " ++ a :}
>>>
f :: IO ()
Yield foo Get Return baz
Documentation
class Dsl k r a where Source #
This type class witnesses a use case of k
,
which is an ad-hoc delimited continuation adaptive to the answer type r
.
Instances
Dsl Empty [r] Void Source # | |
Dsl Empty (Maybe r) Void Source # | |
Dsl k r a => Dsl k (b -> r) a Source # | |
Defined in Control.Dsl.Dsl | |
Dsl Get (State a b) a Source # | |
Dsl (Return r) r Void Source # | |
Dsl (Shift r) r a Source # | |
Monad m => Dsl (Monadic m) (m b) a Source # | |
Dsl (Return r) (IO r) Void Source # | |
Dsl (Return r) (Maybe r) Void Source # | |
Dsl (Return r) [r] Void Source # | |
Dsl (Yield a) [a] () Source # | |
Dsl (Return a) (r !! a) Void Source # | |
Dsl (Put a) (State a b) () Source # | |