Reputation: 141
I am fairly new to Haskell and to programming in general, and I'd like to use Haskell for a project that I have in mind. My major concern is how difficult it will be to write a cross-platform program with Haskell. Ideally, I'd like my final product to work and be easy to install on most Windows, Mac, and Linux machines.
I haven't written any Java, but as I understand it, one of the major strengths of Java is that you can "write once, run anywhere." Since I haven't heard that claim made about Haskell, I assume that a bit more work goes into writing a cross platform Haskell program than in writing a cross platform Java program.
My question is, how much more work are we talking about? If I want my program to work on most Windows, Mac, and Linux machines, how much more of a headache will I be causing myself if I opt to use Haskell instead of a JIT compiled language like Java?
And as a follow-up question:
To what extent can the answer to my first question be applied to all non-JIT compiled languages generally? Are the challenges of creating cross platform software in Haskell more or less equivalent to the challenge of doing so with any other compiled language? How unique is Haskell in this regard?
Thanks!
Upvotes: 3
Views: 1840
Reputation: 10395
Technically, Java is compile once; run everywhere, as it compiles to an intermediate machine-like language. Haskell, like C/C++, compiles to native machine binaries, which means you need to compile everywhere (for every architecture/OS).
Upvotes: 2
Reputation: 12070
You can roughly divide languages into two types- Those that require some type of helper program, and those that are compiled. Examples of languages that need helper software include- Java, which needs the jre, HTML needs a browser, interpreted languages like perl or python need the perl/python interpreter. C/C++ and GHC/Haskell are compiled languages, and can run on their own (Haskell has an interpreter also, but you probably can't assume that your users will have it installed).
There are different challenges associates with each approach. To run Java/HTML/Perl/Python, the user has to install the correct version of the associated helper program, but other than this, you can easily supply one version of your program and assume it will work anywhere. To distribute a compiled program, you generally have to compile it on each target OS and supply a separate version for each one. GHC has been ported to Linux, Mac, and Windows, so you can do this. Compiled programs can run on a target machine without installing anything else.... except perhaps a required library....
Library compatibility can be a problem in both types of languages.... Your user may need to install required libs (package managers like apt can do this automatically). This affects all languages (with or without helper software), and I don't consider it an advantage in one type of language vs another (although some languages like Python, and even Java to some extent advertise "batteries included", meaning that pretty much anything you will want is included in the base install).
So, if you stick to normal libs, and don't mind recompiling for each target platform, Haskell programs can work on all the common systems (much better than C/C++, which use slightly different variants on each OS).
See also Do ghc-compiled binaries require GHC or are they self-contained?
Upvotes: 6