@@ -1,31 +1,23 @@
1+{-# LANGUAGE DeriveAnyClass, DeriveFunctor, DeriveGeneric, DerivingStrategies, FlexibleInstances, GeneralizedNewtypeDeriving,
1−{-# LANGUAGE TypeOperators, FlexibleInstances, KindSignatures, MultiParamTypeClasses, DeriveFunctor, UndecidableInstances, GeneralizedNewtypeDeriving #-}
2+ KindSignatures, MultiParamTypeClasses, TypeOperators, UndecidableInstances #-}
3module Fused.HTTP where
4module Fused.HTTP where
5import Control.Effect
6import Control.Effect
6−import Control.Effect.Sum
7import Control.Effect.Carrier
7import Control.Effect.Carrier
9import Control.Monad.IO.Class
8import Control.Monad.IO.Class
9+import GHC.Generics (Generic1)
11newtype HttpC m a = HttpC { runHttpC :: m a }
11newtype HttpC m a = HttpC { runHttpC :: m a }
12− deriving (Applicative, Functor, Monad, MonadIO)
12+ deriving newtype (Applicative, Functor, Monad, MonadIO)
14data HTTP (m :: * -> *) k
14data HTTP (m :: * -> *) k
15− = Open String k
15+ = Open String (m k)
16− | Close k
16+ | Close (m k)
17− | Post String (String -> k)
17+ | Post String (String -> m k)
18− | HGet (String -> k)
18+ | HGet (String -> m k)
19− deriving Functor
19+ deriving stock (Functor, Generic1)
20−
20+ deriving anyclass (HFunctor, Effect)
21−instance Effect HTTP where
22− handle state handler (Open s k) = Open s (handler . (<$ state) $ k)
23− handle state handler (Close k) = Close (handler . (<$ state) $ k)
24− handle state handler (Post s k) = Post s (handler . (<$ state) . k)
25− handle state handler (HGet k) = HGet (handler . (<$ state) . k)
27−instance HFunctor HTTP where
30open' :: String -> HttpM ()
22open' :: String -> HttpM ()
31open' s = send (Open s (pure ()))
23open' s = send (Open s (pure ()))
@@ -46,7 +38,7 @@ instance (Effect sig, Carrier sig m) => Carrier (HTTP :+: sig) (HttpC m) where
46 Open _ k -> k
38 Open _ k -> k
47 Close k -> k
39 Close k -> k
48 Post s k -> k ("posted " <> s)
40 Post s k -> k ("posted " <> s)
49− HGet k -> k "lmao"
41+ HGet k -> k "lmao"
50 eff (R other) = HttpC (eff (handleCoercible other))
42 eff (R other) = HttpC (eff (handleCoercible other))
52runHttp :: HttpM a -> IO a
44runHttp :: HttpM a -> IO a