windowshaskell

Compiling Haskell (.hs) in windows to a exe


Is it possible to compile a set of .hs haskell files into a exe in windows? .hs -> .exe


Solution

  • Absolutely. Install the Haskell Platform, which gives you GHC, a state-of-the-art compiler for Haskell.

    By default it compiles to executables, and it works the same on Linux or Windows. E.g.

    Given a file:

    $ cat A.hs
    main = print "hello, world"
    

    Compile it with GHC:

    $ ghc --make A.hs
    [1 of 1] Compiling Main             ( A.hs, A.o )
    Linking A.exe ...
    

    Which you can now run:

    $ ./A.exe
    "hello, world"
    

    Note, this was under Cygwin. But the same holds for native Windows:

    C:\temp>ghc --make A.hs
    [1 of 1] Compiling Main             ( A.hs, A.o )
    Linking A.exe ...
    
    C:\temp>A.exe
    "hello, world"