
David Roundy wrote:
If only we had type families already, then we could define
-- These data constructors are exported data Inherit = Inherit data CreatePipe = CreatePipe data UseHandle = UseHandle Handle data NewHandle = NewHandle Handle
-- This class is not exported! (so CreateProcess needn't worry about new -- instances sowing up) class StdStream s where type Out s isInherit :: s -> Bool isCreatePipe :: s -> Bool isHandle :: s -> Maybe Handle
instance StdStream Inherit where type Out Inherit = () ...
instance StdStream IsHandle where type Out IsHandle = () ...
instance StdStream CreateProcess where type Out Inherit = NewHandle ...
data CreateProcess sin sout serr = CreateProcess { cmdspec :: CmdSpec cwd :: (Maybe FilePath) env :: (Maybe [(String, String)]) std_in :: sin std_out :: sout std_err :: serr close_fds :: Bool }
createProcess :: (StdStream sin, StdStream sout, StdStream serr) => CreateProcess sin sout serr -> IO (Out sin, Out sout, Out serr, ProcessHandle)
Yes, this is neat. I also played around with an alternative formulation using GADTs, but decided against it because of course System.Process is supposed to present a portable API. I sure hope we can add something like this in the future though. Cheers, Simon