0

Reading http://blog.haskellformac.com/blog/running-command-line-programs :

This requires installing the Haskell for Mac command line tools as outlined in a previous article. Those tools include a command named runhaskell, it runs a Haskell program in "script mode" — i.e., it is being interpreted, instead of compiled (much like, say, the Python interpreter runs a Python script).

Why provide a tool to run haskell in script mode ?

As the code is being interpreted does this mean it will run slower in script mode ?

blue-sky
  • 51,962
  • 152
  • 427
  • 752

1 Answers1

4

Yes, it will run slower, but depending on the application this may not matter at all. Many interesting tasks don't in fact require a lot of computations, so you wouldn't even notice the runtime difference between, say, Java and Ruby, though the latter is considered to have much worse performance.

For such quick-run applications, what's rather more important is the startup time. With interpreted languages, this is often pretty immediate, whereas recompiling a script can take considerable time. So, interpreting can indeed be faster that compiling, in practise!

Furthermore, just because the script is interpreted doesn't mean every single computation is. In fact, most of the critical stuff is often defined in libraries which are compiled and only called from the interpreted code – this is the single reason why languages like Python or Matlab can be competitive in scientifc computing: the computationally intensive routines are actually written in compiled C or Fortran, not the top-level language itself!

Haskell gives you the advantages of both worlds (fast raw performance of a compiled language; quick usage and conciseness of an interpreted one), but without the need to actually have two different languages – you can simply choose which parts to run compiled and which to merely interpret!

(This is not to say that this is a unique thing about Haskell – there exist in fact interpreters for pretty much all compiled languages. Only, it's normally not that common to run code interpreted except for debugging. But Haskell turns out to be well-suited even for scripting tasks that might normally be written in Python or Bash, but which nobody would bother to procure an entire Java or C++ project for.)

leftaroundabout
  • 117,950
  • 5
  • 174
  • 319