The new HTTP library

Written by Jeff Heard on January 16th, 2009

I pulled down the new HTTP library the other day to see how much of a difference the ByteString enabled downoading would make to my performance.  Wow.  I went from 1.503 seconds for a 5mb image download from the apache server on my own machine to 0.053 seconds with the new HTTP library.  Previously, I’d been using HTTP-Simple, but now I’ve rewritten the HTTP-Simple’s single export function httpGet to use bytestrings.

It’s not pretty, but I didn’t have to change a lot of code to get all the benefit.  Note, openURI a function exported by Network.Download.Curl, and httpGet is a function exported by Network.HTTP.Simple.  These were the only two functions I used in the program I’ve been working on, so I just wrote the following code to replace them:

module HTTPSimple where

import Network.Stream
import Network.HTTP
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as CS
import System.Environment
import Network.URI
import Data.Maybe
import Control.Monad

openURI :: String -> IO (Either String BS.ByteString)
openURI url = do
    result <- simpleHTTP $ Request (fromJust . parseURI $ url) GET [] BS.empty

    case result of
        Right (Response _ _ _ body) -> return (Right body)
        Left err -> return (Left . show $ err)                                                    

httpGet :: URI -> IO (Maybe String)
httpGet url = do
    result <- simpleHTTP $ Request url GET [] CS.empty

    case result of
        Right (Response _ _ _ body) -> return (Just . CS.unpack $ body)
        Left err -> return Nothing

Beautiful Code, Compelling Evidence

Written by Jeff Heard on January 16th, 2009

Beautiful Code, Compelling Evidence. Purely Functional Information Visualization

This is a tutorial I presented at ICFP last year on visualization and graphics in Haskell.  It talks at length about why functional programming is a good idea for graphics, and then presents the basic tools that exist today.

I’m continuing that work right now with an interest in developing declarative systems that provide a graphics as a transformational layer from pure data.  Non basic tools that don’t yet exist today.  In other words, you don’t draw graphics based on data — the graphics are a function on the data and user interactions on the data.  Hopefully, this will lead to better, easier ways of building visualizations and will also lead to code that is directly understandable and predictable in terms of the data.