[Haskell-cafe] When is waitForProcess not necessary?

Dougal Stanton ithika at gmail.com
Fri Aug 3 04:28:10 EDT 2007

On 03/08/07, Dave Bayer <bayer at math.columbia.edu> wrote:
>  I'm actually calling
> Markdown.pl on tiny files (source code of lengths a human would read), and
> it is certainly sluggish enough to be a fair test.)

I had to do this recently, so you might be interested in my approach:


The idea here is to run arbitrary text (blog posts) through Markdown
and Smartypants before sending them out to the wider world. The code
should be pretty self-contained and easy to follow. It does use
waitForProcess but I've done my best to keep it clean. (It could still
do with being refactored though; there are still bits or repeated

The part you want is about 80% of the way down and looks like this:

educate = \s -> markdown s >>= smartypants

markdown = convert "Markdown"
smartypants = convert "SmartyPants"

convertWith conv str = do
    (hin, hout, herr, proc) <- runInteractiveProcess conv [] Nothing Nothing
    forkIO $ hPutStr hin str >> hClose hin
    str' <- hGetContents hout
    return (str', proc)

convert conv input = do
        (convertWith conv input)
        (\(_,pc) -> do
            ret <- waitForProcess pc
            return (ret==ExitSuccess))
        (return . fst)



More information about the Haskell-Cafe mailing list