Library proposal: Add System.Info.isWindows

Ian Lynagh igloo at earth.li
Tue Aug 7 08:04:59 EDT 2007


On Mon, Aug 06, 2007 at 01:36:54PM +0100, Neil Mitchell wrote:
> 
> Proposal:
> 
> Add System.Info.isWindows :: Bool

I was actually planning to propose something along similar lines this
week, in order to replace ifdef's like in the GHC and library sources with
pattern matches like I have done in Cabal, e.g.:

-#if mingw32_HOST_OS || mingw32_TARGET_OS
-dllExtension = "dll"
-#else
-dllExtension = "so"
-#endif

+dllExtension = case os of
+                   Windows _ -> "dll"
+                   _         -> "so"

I haven't been through to look at what ifdef-replacements are needed,
but I expect to want both
    OS = Linux | Windows Windows | ... | OtherOS String
and
    Arch = I386 | AMD64 | Sparc | ... | OtherArch String
types.

Not all ifdefs will be able to be removed, e.g. because they use
platform-specific packages or foreign imports. I don't know if it would
be worth having other extensions to make elmiinating these ifdefs
possible too.

I would like it to be easy for an optimiser to dead-code-eliminate
branches that don't apply (and in particular I would like it to be
something that is DCEd by GHC so we don't carry around entire NCGs we
can't use, for example).
As long as that happens I don't really mind if it is done by pattern
matching or by using isWindows-style functions. Doing equality tests
against System.Info.os doesn't cut it, though.

Finally, it needs to remain in base if we are to use it for
ifdef-removal in the base libraries (and as low down in base as
possible).

> > data OS = Linux | Windows Windows | ... etc | Other String
> > data Windows = MingW
> 
> Since when did GNU build Windows operating systems?

It seemed to me that at some point we would be likely to want to
distinguish between MingW | Cygwin | Native, but a lot of the time we'd
want to just match Windows _.

> You can add
> System.Info.libraries :: [Libary], and make MingW a library, but if
> you have a Windows enumeration it really should be for a list of
> Windows operating systems.

We'd need to do IO to do that, so it wouldn't fit my needs. Also,
    MingW `elem` libraries
wouldn't get optimised out at compile time.


It would be great if we could get all this into 6.8, as then we will be
able to rely on it a year or so earlier.

> There are lots of things that could go in System.Info, and I agree
> more should be moved along.

Ditto for these.


Thanks
Ian



More information about the Libraries mailing list