POpen

Jens Petersen petersen@redhat.com
06 Mar 2002 12:42:27 +0900


"Simon Marlow" <simonmar@microsoft.com> writes:

> I would drop the file into the tree as hslibs/posix/POpen.hs for now,

Ok, sure.  (Btw is there is a LICENSE file for hslibs?)

> and export popen and popenEnvDir from Posix.

I have been pondering a little over popenEnvDir.  I'm
starting to think it might be preferable to have some idioms
like "withCurrentDirectory" and "withEnv" instead.

        withCurrentDirectory :: FilePath -> IO a -> IO a
        -- in DirectoryExts perhaps, or System.Directory?
        withEnv :: [(String, String)] -> IO a -> IO a
        -- in SystemExts perhaps, or System.Environment?

Well, "executeFile" takes a Maybe Env argument, so maybe
that it ok, but perhaps the Dir part could be dropped (it
basically comes from runProcess) to make "popenEnv" instead?
In that case perhaps just one function "popen" is enough,
don't you think?

> > Btw is most of hslibs expected to go into libraries?
> > How about all the posix stuff?
> 
> The plan is to migrate everything useful from hslibs into libraries
> eventually.  Deprecated functionality and old interfaces are being left
> behind, and someday we'll ship GHC without hslibs at all.  Hugs is also
> going to move to using the contents of fptools/libraries for its base
> libraries soon.

So libraries will be the new library base in the next release of ghc?

> As regards the Posix library, I think we need a redesigned library that
> supports more of IEEE 1003.1-2001 (the latest incarnation of POSIX
> including all the extra bits from the Single Unix Spec).  It certainly
> needs to be completely re-implemented: the current Posix library uses
> all kinds of old GHC features and libraries that we'd like to remove.

Ok.  The Posix popen seems to allow only reading from or
writing to the subprocess, but not both.

I wonder if something like the following sugar wouldn't be
useful too?

        withStdinString :: String -> IO a -> IO a
        withStdoutString :: IO a -> IO (a, String)
        withStdoutString_ :: IO () -> IO String
        withStderrString :: IO a -> IO (a, String)
        withStderrString_ :: IO () -> IO String
        withStdouterrString :: IO a -> IO (a, String)
        withStdouterrString_ :: IO () -> IO String

> > Yes, that's ok.  Should I send you a new version with the
> > header updated
> 
> That would be great, thanks.

Ok, basically it's ready, pending any changes from comments
to the above.

Jens