Skip to content

Instantly share code, notes, and snippets.

@markhibberd
Forked from tonymorris/gist:3223507
Created August 1, 2012 04:10
Show Gist options
  • Save markhibberd/3223553 to your computer and use it in GitHub Desktop.
Save markhibberd/3223553 to your computer and use it in GitHub Desktop.
Yo
import Data.Monoid
import Control.Monad.State
import Control.Monad.Reader
data RequestHeaders =
RequestHeaders [(String, String)]
data ResponseHeaders =
ResponseHeaders [(String, String)]
data Session =
Session [(String, String)]
data Log =
Log [String]
data Config =
Config String
data InputStream =
InputStream (IO Char) (IO Bool)
data OutputStream =
OutputStream (Char -> IO ())
data HttpResponse =
HttpResponse ResponseHeaders OutputStream
-- MaybeT (Writer Log) a
data Result a =
Result Log (Maybe a)
-- MaybeT (WriterT Log f) a
data ResultT f a =
ResultT (f (Result a))
{-
<dibblego> @unmtl MaybeT (WriterT Log (ReaderT (RequestHeaders, Config) (StateT (ResponseHeaders, Session) f))) a
<lambdabot> RequestHeaders -> Config -> ResponseHeaders -> Session -> f (Maybe a, Log, ResponseHeaders, Session)
-}
data Run f a =
Run (ResultT (ReaderT (RequestHeaders, Config) (StateT (ResponseHeaders, Session) f)) a)
data Json =
Json String
type X = Run IO
setHeader :: String -> String -> X ()
setHeader = error "todo"
getHeader :: String -> X (Maybe String)
getHeader = undefined
finish:: Int -> String -> X ()
finish = undefined
{-
xxxxx =
when somethingIsShit (finish 123 "asfsaf") >> setHeader "213" "1223"
-}
run :: X Json -> IO Log
run =
undefined
data RWST f r w s a =
RWST (r -> s -> f (w, s, a))
data DoWe a = DoWe (ResponseHeaders -> Either ResponseHeaders a)
swizzle ::
(w, Either a x)
-> Either a (w, x)
swizzle (_, Left a) =
Left a
swizzle (w, Right x) =
Right (w, x)
swozzle ::
Monoid w =>
Either a (w, x)
-> (w, Either a x)
swozzle (Left a) =
(mempty, Left a)
swozzle (Right (w, x)) =
(w, Right x)
class Functor f => Extend f where
extend ::
(f a -> b)
-> f a
-> f b
class Extend f => Comonad f where
extract ::
f a
-> a
instance Extend ((,) t) where
extend f (t, a) =
(t, f (t, a))
instance Comonad ((,) t) where
extract =
snd
data Run' f g a =
Run' (ResponseHeaders -> RequestHeaders -> Config -> Session -> Either (f Log) (g (ResponseHeaders, Session, Log, a)))
@thomasdavis
Copy link

suga suga

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment