How do you test executable Haskell files
Haskell in 5 steps
Haskell is a universal and purely functional programming language. This page should help you get started as soon as possible.
Haskell, like many other languages, comes in two different types: batch processed (Compiler) and interactive (interpreter). An interactive system provides you with a command line in which you can experiment and evaluate expressions directly. It is probably a good choice to start with.
|GHC||Compiler and Interpreter (GHCi)||Probably the most complete system.|
|Hugs||Interpreter only||Very portable and lighter than the GHC.|
While both GHC and Hugs run on Windows, Hugs is probably best integrated with Windows. Nonetheless, GHC is being more actively developed and maintained. In addition, there seems to be a consensus that the GHC is the development environment of choice for beginners and old hands. There is also information on installing Haskell software on Mac OS X.
Open a terminal. Tap ghci (the name of the GHC interpreter executable file) if you have GHC installed. If you have Hugs installed, give hugs a.$ ghci ___ ___ _ / _ \ / \ / \ / __ (_) / / _ \ // / _ / / / | | GHC Interactive, version 6.4, for Haskell98. / / _ \ / __ / / ___ | | http://www.haskell.org/ghc/ \ ____ / \ / / _ / \ ____ / | _ | Type:? for help. Loading package base-1.0 ... linking ... done. Prelude>
You will be shown a prompt and Haskell is now waiting for your input.
Write your first Haskell program
If you have learned another programming language, your first program was probably "Hello, World!". Let's start with that.
Haskell evaluates the string and displays the result. We can also vary and display it directly from the standard output:
With a Haskell compiler like the GHC, you can compile the source code into an executable single application. Create a file hello.hs with the content:
And compile it with:$ ghc -o hello hello.hs
You can now execute the result (./Hello under Unix systems, hello.exe under Windows):$ ./hello Hello, World!
Haskell as a calculator
Now for something more interesting. Your first real Haskell program is the faculty function.
This defines a new function fac which computes the factorial of an integer.
We can now fac call with one argument:
Congratulations! Programming made easy. Note that in Hugs, the definition of fac from a file fac.hs that includes:
In Hugs it needs to be done like this (this also works in GHCi):
Of course, we can also compile this program to create a stand-alone program. We can now go into the file using pattern matching fac.hs write the following:
This can then be compiled and executed:$ ghc -o fac fac.hs $ ./fac 1405006117752879898543142606244511569936384000000000
Write your first parallel Haskell program
Haskell has good support for parallel and multicore programming. We write a parallel Haskell program by adding `par` to the respective expression.
This program is then compiled with the -threaded flag and optimizations:$ ghc -O2 --make A.hs -threaded [1 of 1] Compiling Main (A.hs, A.o) Linking A ...
Now we can run our program, in this example with two cores:$ time ./A + RTS -N2 1405006117752879898543142606244511569936384005711076 ./A + RTS -N2 2.14s user 0.02s system 149% cpu 1.449 total
Congratulations! Now you program your multicore processor!
How it goes on
There are plenty of good Haskell tutorials and books out there. Here are some we recommend:
A complete list of textbooks and specialist books as well as tutorials and other recommendations can be found here:
Join the community!
Chat with members of the Haskell community:
Languages: deenturzh / cnzh / twja
- What are advances in ATMs
- How is dominant Costa Rica
- Why do stab wounds hurt so much
- What exactly is vaccination for children
- Can a homeless person get a passport
- Which sex tablet can I use
- What are some storage software
- How is life at Lovely Professional University
- How to make a baby
- Why is grateful written differently than great
- Why should people switch to LED lamps
- Why do we call direct debit as Dr
- Are sports organizations corrupt
- Can we overcome procrastination with mindfulness?
- What's in vegan calamari
- In DBS, who is the strongest angel
- Why is Telegram free
- What makes an application addicting
- What noise does a fire engine make?
- Can the human brain grow new neurons
- What is the SAS exam in SSC
- What is the nucleic acid amplification test
- Easier to find peace than happiness
- What is implied volatility in options trading