Proposal: Add getFullProgName

Johan Tibell johan.tibell at
Tue Jun 19 18:41:33 CEST 2012

On Tue, Jun 19, 2012 at 9:30 AM, Simon Hengel <sol at> wrote:

> >  * we can't implement this reliably,
> If I understand correctly the current System.Environment.getProgName can
> make this distinction somehow.  But from a quick peek at the code, I
> can't really tell how it's done.

It doesn't. It returns whatever string follows the last / in argv[0].
argv[0] can in theory be anything, including "my hair is on fire." :) See
the earlier posts in this thread.

I don't think it's possible to implement this correctly, except if we
change how GHC runs scripts (i.e. by setting an environment variable, but
if you do that you might as well just check for the environment variable if
you want to know if you're running as a script.)

>  * the distinction into these three groups doesn't necessarily work for
> all
> > compilers, and
> If a compiler does not support script/interactive, it could always
> return Binary, right?

It might also have some 4th, non-compatible option. Even if it only haves a
subset, it forces the programmer to write a pattern match that doesn't make
sense (as some of the options can never happen.) getExecutablePath :: IO
FilePath doesn't have this problem, as it's always defined.

>  * the distinction (I assume) isn't useful in most use cases
> At this point I would find it useful to define use cases.  When I was
> looking for that functionality, I wanted to find files relative to a
> script.  For binaries I use Cabal's support for data files, but this
> only works for `cabal install`ed packages.

I guess my point is that we cannot implement what you want correctly. We
can implement a heuristic that kind-of works most of the time. That's a
useful thing to have, but if so as a function built upon a more
well-defined getExecutablePath.

> I think people who want to use this heuristic are better served by the
> > existing executable-path package. What do you think?
> I still think that a well-tested, reliable way to do that would be
> awesome.  I'm not sure how hard it is to get it right, though.
> If we do not support interactive/script, then I think we should at least
> use a Maybe instead of `error`.

getExecutablePath :: IO FilePath

is always defined. It returns the path to the currently running executable,
which is e.g. /bin/ghc in case of a script.

-- Johan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list