Skip to content

Instantly share code, notes, and snippets.

@owickstrom
Created May 12, 2015 11:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owickstrom/736765956c91350faeda to your computer and use it in GitHub Desktop.
Save owickstrom/736765956c91350faeda to your computer and use it in GitHub Desktop.
Rackla Types (in my mind, at least)
module Main where
import Control.Applicative
-- value with type a is only for demo purposes, it would be supplied
-- asyncronously in Rackla (or with messages, I don't know how it works
-- exactly).
data PID a = PID a deriving (Show)
instance Functor PID where
fmap f (PID p) = PID (f p)
data Rackla a = Rackla [PID a] deriving (Show)
instance Functor Rackla where
fmap f (Rackla pids) = Rackla (map (fmap f) pids)
----------------------------------------
-- Here begins the Rackla.HTTP module,
-- which is the fun stuff.
----------------------------------------
type Response = String
-- Create some responses, which are just the request URLs in this demo.
request :: [String] -> Rackla Response
request urls = Rackla $ map (\x -> PID $ "Request for " ++ x) urls
-- Dummy implementation of some transforming function.
setSomeHeader :: Response -> Response
setSomeHeader = id
main :: IO ()
main = print (setSomeHeader <$> request ["some", "crazy", "urls"]) -- <$> is infix "fmap"
@owickstrom
Copy link
Author

This has no asynchronicity at all for the purpose of being terse.

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