[Haskell-cafe] Re: HSH and IO ()

Dimitry Golubovsky golubovsky at gmail.com
Sat Jun 13 08:20:10 EDT 2009


Thanks for the reply.

In this case, would the body of my function run in a separate thread
via forkProcess (that's what is needed, maybe I didn't make it clear)?

In my previous project, I had to do like this (probably not very
portable, at least requires System.Posix):

  (fd1, fd2) <- createPipe
  hscfd <- fileToFd hscFile
  hscpid <- forkProcess $ redirFd fd1 0 $
                          redirFd fd2 (-1) $
                          redirFd hscfd 1 $
                          hsffigMain (fromJust $ gccPath dopt)
                                     (inclDirs dopt) minusD
  gccpid <- forkProcess $ redirFd fd2 1 $
                          executeFile (fromJust $ gccPath dopt)
                                      (["-E", "-dD"] ++
                                       minusI ++ minusD ++
  closeFd hscfd
  closeFd fd1
  closeFd fd2
  gccrt <- getProcessStatus True False gccpid
  hscrt <- getProcessStatus True False hscpid


where hscpid corresponds to a process that runs a Haskell function
(hsffigMain :: a -> b -> c -> IO ()) defined within the same program,
and gccpid runs an external program (gcc), and they are piped
together. I am trying to avoid writing this mess using HSH.

I'm just trying to find out whether this was already done. If not,
what is the best way to write the above to be integrated into HSH (I'd
be glad to contribute).

Thank you.

On Sat, Jun 13, 2009 at 12:46 AM, John Goerzen<jgoerzen at complete.org> wrote:
> You can replace it with a function that can take any Channel, and
> produce a result as a Channel of one particular sort.  In particular,
> this instance:
> instance ShellCommand (Channel -> IO Channel) where

Dimitry Golubovsky

Anywhere on the Web

More information about the Haskell-Cafe mailing list