Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I have made some simple functions to find the first SO chat message. How can I improve my code?

Even if there is a stackoverflow link that will get the job done (I'd be glad to know), I'd like to improve upon my already written code.

import Network.HTTP
import Text.Regex.Posix

type UserID      = String
type MessageLink = String
type PageNumber  = Integer

findLast :: UserID -> IO MessageLink
findLast = searchLast 1 "Not found" 

searchLast :: PageNumber -> MessageLink -> UserID -> IO MessageLink 
searchLast pg lnk id = do

    let link = "http://chat.stackoverflow.com/users/" ++
               id ++ "?tab=recent&page=" ++ show pg 

    c <- simpleHTTP (getRequest link) >>= getResponseBody

    let match = c =~ "/transcript/[^\"]+" :: [[String]]

    if null (c =~ "monologue" :: String)
        then return $ "http://chat.stackoverflow.com" ++ lnk
        else searchLast (pg + 1) (head . last $ match) id
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.