Introduction

Haskell is a general purpose, purely functional programming language incorporating many recent innovations in programming language design.

Haskell provides higher-order functions, non-strict semantics, static polymorphic typing, user-defined algebraic datatypes, pattern-matching, list comprehensions, a module system, a monadic I/O system, and a rich set of primitive datatypes, including lists, arrays, arbitrary and fixed precision integers, and floating-point numbers.

Haskell is both the culmination and solidification of many years of research on lazy functional languages.

Haskell is lazy, that means that unless specifically told otherwise, Haskell won't execute functions and calculate things until it's really forced to show you a result. That goes well with referential transparency and it allows you to think of programs as a series of transformations on data.

C, Java, Pascal, Ada, and so on, are all imperative languages. They are "imperative" in the sense that they consist of a sequence of commands, which are executed strictly one after the other. Haskell is a functional language. A functional program is a single expression, which is executed by evaluating the expression.

Another interesting feature of functional languages like Haskell: functions are treated as values like integers (numbers) and strings. You can add a function to another function the way you can add an integer to an integer, 1 + 1 or 35 + 53.

Haskell programs are a series of high-level generalizable functions that define what the program is intended to do, letting lower layers (compiler, runtime, and libraries) handle mundane low-level details such as iteration. Its foundation is a strong static type safety and inference system.

The compiler enforces the type check and produces clean, concise and correct code with little side effects from the outset.

Features of Haskell

  • Haskell is a purely functional programming language.
  • Referential transparency.
  • Haskell is lazy.
  • Programs as a series of transformations on data.
  • Haskell is statically typed
  • Haskell uses a very good type system that has type inference.
  • Haskell is elegant and concise.
  • Haskell was made by some really smart guys.
  • Haskell is a completely free language to use

Haskell Compiler

The Glasgow Haskell Compiler is a state-of-the-art, open source compiler and interactive environment for the functional language Haskell.

The Glasgow Haskell Compiler (GHC) started as part of an academic research project funded by the UK government at the beginning of the 1990s

Over its lifetime GHC has generally had around two or three active developers, although the number of people who have contributed some code to GHC is in the hundreds.

The Compiler

We can divide the compiler into three:

  • The compilation manager, which is responsible for the compilation of multiple Haskell source files.
  • The Haskell compiler (we abbreviate this as Hsc inside GHC), which handles the compilation of a single Haskell source file.
  • The pipeline, which is responsible for composing together any necessary external programs with Hsc to compile a Haskell source file to object code

Install Haskell

  • Go to official download page :
  • install-haskell
  • Download the file based on your requirement, I am downloading Full
  • Open the downloaded exe file
  • installation-wizard
  • Select the path for Haskell Installation
  • select-path-for-haskell-install
  • It will take few minutes to complete the installation
  • progress-installation-haskell
  • On the completion of installation you might see a screen like below image.
  • finish-haskell-installation
  • After installation, lets verify the installation. For that please open your cmd/terminal and type ghci command in terminal, if you see output like below one then your installation is successful.
  • verify-haskell-installation

Hello world in Haskell

It is basic ritual kind of thing to write hello world in programming languages, so lets write hello world program in Haskell.


Prelude> "Hello, World!"
"Hello, World!"

The Haskell system evaluated the string, and printed the result. Or we can try a variation to print directly to standard output:


Prelude> putStrLn "Hello World"
Hello World

Instead of running interactively you can compile files to create an executable. The -o option lets you specify the name of the output file. The input file in this example is hello.hs We can't just drop in a putStrLn call the way we would with something like Python. We have to define a main function.

When the program is run that will be the main entry point, just like all other languages. Here is the contents of hello.hs.


main = putStrLn "Hello, world!"

Compile it with


ghc -o hello hello.hs


./hello

About Author

Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.

Share this Article Facebook
Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions

Recent Addition

new tutorial Protractor Online Training : I am starting online training course for Protractor with Typescript from 15th November 2018.

You can attend first 3 classes for free, the total course fee is INR 10,000

The course time would be 8.00 PM(IST) for the first three classes

The course time would be 8.00 PM(IST) for the first three classes

If you are interested to learn then you can join the course by sending email to chercher.tech@gmail.com

or Register below


Subscribe
 
Join My Facebook Group
Join Group