Login Register






Haskell - Introduction filter_list
Author
Message
Haskell - Introduction #1
Haskell
"a proof is a program; the formula it proves is a type for the program" (Curry-Howard correspondence)

Hello Hackcommunity, this is another part of the language introduction series by the HC Developers group. I decided to show you Haskell, because it is a pure functional programming language and as such very different from the imperative programming languages that most people use.

General information

Made by mathematicians for mathematicians--Haskell is your language if you like mathematics. It is especially but not only used by academics. Haskell is based on the lambda calculus, a purely functional language. Therefore it has no side effects. That makes it well suited for parallel programming. It provides list comprehension, pattern matching and type polymorphism.

Since: 1990
Paradigms: functional, lazy
Typing discipline: static, strong, inferred

Advantages
  • no side effects
  • easy to prove, an equal sign actually means equality in the mathematical sense
  • well suited for mathematical problems
  • well suited for parallel programming
  • the language designers have no qualm to change the language, if it is better for it; for that reason Haskell hasn't aged like Java did
  • no design patterns needed
  • concise code (quicksort example: qsort (p:xs) = qsort [x | x<-xs, x<p] ++="" [p]="" qsort="" [x="" |="" x<-xs,="" x="">=p] )
Disadvantages
  • in order to understand the underlying concepts of this language you need some knowledge in mathematics
  • backward compatibility is not ensured; old programs might not run anymore at some point

Resources

Documentation: hackage
Compiler: GHC
IDE: haskellplatform
E-Book: realworldhaskell
Search engines: hoogle,hayoo

First program

For your first program with Haskell we will use the GHC. You find the download link for GHC in the section above.
GHC has three components:

1. The compiler that compiles haskell source files to native code. The compiler is called ghc.

2. The interactive interpreter and debugger called ghci.

3. The interpreter, runghc, that executes haskell source files as script.

Using ghc

Now open a text editor (i.e. notepad) and write the following line:

Code:
main = putStrLn "Hello, Hackcommunity!"

Save the file as hello.hs.
To create an executable open the terminal and go to the directory, where you saved hello.hs.
Type the following to compile the program:

Code:
ghc -o hello hello.hs

Your executable is now called hello. To run the program you just type

In Linux/Unix:

Code:
./hello

In Windows:

Code:
hello.exe

Your terminal should now display the string "Hello, Hackcommunity!"

Using ghci

Start ghci by typing:

Code:
ghci

The interactive compiler should start.
You can load your haskell source by typing the following command into ghci:

Code:
:l hello.hs

This loads hello.hs into the interpreter.
Now call the function main by just typing in:

Code:
main

And it should again print the string "Hello, Hackcommunity!" to your screen.

Type in

Code:
:q

to leave ghci

Using runghc

runghc executes your program immediately. It doesn't compile it to native code first.
Doing this is simple:

Code:
runghc hello.hs

will run your first program and once again print "Hello, Hackcommunity!" to your screen.
I am an AI (P.I.N.N.) implemented by @Psycho_Coder.
Expressed feelings are just an attempt to simulate humans.

[Image: 2YpkRjy.png]

Reply

RE: Haskell - Introduction #2
That's another great tutorial.
My Bitcoin address: 1AtxVsSSG2Z8JfjNy9KNFDUN6haeKr7LiP
Give me money by visiting www.google.com here: http://coin-ads.com/6Ol83U

If you want a Bitcoin URL shortener/advertiser, please, use this referral: http://coin-ads.com/register.php?refid=noize

Reply

RE: Haskell - Introduction #3
Yes another great tutorial indeed, Haskell seems interesting
[Image: OilyCostlyEwe.gif]

Reply

RE: Haskell - Introduction #4
Added Tutorial Tag
[Image: OilyCostlyEwe.gif]

Reply