On 11/18/07, Benja Fallenstein <[EMAIL PROTECTED]> wrote:
> Hi Radosław,
>
> You should be able to write this with MaybeT as follows:

Correction, sorry. The code in my original mail doesn't take care of
converting the 'Maybe's returned by the functions you're calling into
'MaybeT's.

The following should work, but is a little annoying:

getStrip :: IO ( Maybe String )
getStrip = runMaybeT $ do
    pageContent <- MaybeT $ downloadFile mainPageAddress
    z <- MaybeT $ return $ patternForStrip pageContent
    MaybeT $ downloadFile $ mainPageAddress ++ z

Something like the following might feel cleaner, though:

maybeT :: Maybe a -> MaybeT m a
maybeT = MaybeT . return

downloadFile :: String -> MaybeT IO String
downloadFile s = maybeT (parseURI s) >>= liftIO . httpGet

getStrip :: MaybeT IO String
getStrip = do
    pageContent <- downloadFile mainPageAddress
    z <- maybeT $ patternForStrip pageContent
    downloadFile $ mainPageAddress ++ z

Best,
- Benja
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to