@@ -0,0 +1,40 @@
1+{-# LANGUAGE DataKinds, TypeOperators, GADTs, FlexibleInstances, MultiParamTypeClasses #-}
2+
3+module ExtEff.HTTP where
4+
5+import Control.Eff
6+import Control.Eff.Extend
7+import Data.Function
8+
9+type HttpM = Eff '[HTTP, Lift IO]
10+
11+data HTTP a where
12+ Open :: String -> HTTP ()
13+ Close :: HTTP ()
14+ Post :: String -> HTTP String
15+ HGet :: HTTP String
16+
17+open' :: String -> HttpM ()
18+open' = send . Open
19+
20+close' :: HttpM ()
21+close' = send Close
22+
23+post' :: String -> HttpM String
24+post' = send . Post
25+
26+get' :: HttpM String
27+get' = send HGet
28+
29+instance Handle HTTP r b (Eff e b) where
30+ handle h q req = case req of
31+ Open _s -> h (q ^$ ())
32+ Close -> h (q ^$ ())
33+ Post s -> h (q ^$ ("posted " <> s))
34+ HGet -> h (q ^$ "contents")
35+
36+doHttp :: Eff (HTTP ': e) b -> Eff e b
37+doHttp = fix (handle_relay pure)
38+
39+runHttp :: HttpM a -> IO a
40+runHttp = runLift . doHttp