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