Created
May 12, 2015 11:09
-
-
Save owickstrom/736765956c91350faeda to your computer and use it in GitHub Desktop.
Rackla Types (in my mind, at least)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has no asynchronicity at all for the purpose of being terse.