Haskell - Introduction: Why you should learn Haskell!

in programming •  7 years ago  (edited)

Untitled.png

What is Haskell?

Haskell is a purely functional programming language. C, C++, Java, Pascal, Python etc. are all examples of imperative programming languages. In imperative programming languages, you give a computer a sequence of commands and the computer executes these commands one after the other. These statements are said to change the state of the program as each one is executed in turn. For example, in imperative programming languages you can set a variable x to 10, do some stuff and then set that variable x to something else if you want. In purely functional programming you cannot do this – variables do not exist! (not ones that change their value, anyway) Instead you tell the computer what stuff is rather than what it should do.

Example:

The factorial function takes a number n and returns

n × (n − 1) × (n − 2) × · · · × 2 × 1

So factorial(5) = 5 × 4 × 3 × 2 × 1 = 120

How would you write a program to compute factorial(n)?

The imperative way:

Untitled.png

This program is a sequence of commands that the computer will execute one after the other. The program tells the computer to:

  1. Declare variables
  2. Go around a while loop
  3. Do these instructions each time

The functional way:

Untitled.png

This python program still computes factorial(n) but:

  1. No variables are declared
  2. Recursion is used instead of explicit looping

Functional programs are more mathematical

  • No variables
  • No loops
  • Uses recursion

If you’re already proficient with imperative or object-oriented languages, then learning to think functionally can be challenging. In a lot of ways, it requires you to become a beginner all over again. You’ll have to change your habits and learn how to solve problems in a functional way.

So Why Learn a Functional Language?

In multi-paradigm languages you can incorporate different approaches the language supports. Instead, functional languages will force you to use a functional approach throughout which make them have better syntactic support for functional techniques than multi-paradigm languages.
Haskell is the language that any that any functional programmer worth his/her salt knows. However, not many people make a living coding in Haskell as adoption in industry is very limited. But is it growing more important, especially as parallel systems are becoming more prominent, e.g. multi-core GPUs. Functional programming is great for parallel systems.

Learning a functional language such as Haskell will also make you a better programmer in general. You don’t necessarily need to use a functional programming language to do functional programming but sometimes the functional style is most appropriate. Learning Haskell will force you to become proficient with a functional style of programming.

Image Source: https://en.wikipedia.org/wiki/Haskell_(programming_language)

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @marrc! You have completed some achievement on Steemit and have been rewarded with new badge(s) :

Award for the number of upvotes

Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here

If you no longer want to receive notifications, reply to this comment with the word STOP

By upvoting this notification, you can help all Steemit users. Learn how here!

Congratulations @marrc! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 1500 upvotes. Your next target is to reach 1750 upvotes.

Click here to view your Board of Honor
If you no longer want to receive notifications, reply to this comment with the word STOP

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @marrc! You received a personal award!

1 Year on Steemit

Click here to view your Board of Honor

Support SteemitBoard's project! Vote for its witness and get one more award!

Congratulations @marrc! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!