Proposal: Add getFullProgName
apfelmus at quantentunnel.de
Sat Jun 16 09:51:18 CEST 2012
Johan Tibell wrote:
> getProgName is only useful in case you want to print the program name
> to the screen. You cannot actually use it to do anything interesting
> programmatically (like execv:ing the program.) I suggest we add
> getFullProgName which does the sensible thing of returning argv.
> Here's an implementation:
> getFullProgName :: IO String
> getFullProgName =
> alloca $ \ p_argc ->
> alloca $ \ p_argv -> do
> getFullProgArgv p_argc p_argv
> peek p_argv >>= peek >>= peekCString
> foreign import ccall unsafe "getFullProgArgv"
> getFullProgArgv :: Ptr CInt -> Ptr (Ptr CString) -> IO ()
While getFullProgramName is a very useful function, I don't think that
the proposed implementation is any good.
The trouble is that getFullProgramName needs to be portable across
different platforms. If it works on UNIX platforms but not on any other
platform (Windows? Android?), we will just end up with Haskell code that
works correctly only on UNIX, and subtly breaks everywhere else. I don't
think that this is a good idea.
Also, the package
provides a portable way to get the path of an executable. If more
standardization is required, I would argue that we should include it in
the Haskell Platform or integrate the source code into base.
More information about the Libraries