TechAlpine – The Technology world

Clojure, Haskell and Erlang – A brief overview

Clojure Haskell and Erlang

Clojure Haskell and Erlang – Let’s Explore

Introduction :

Programming languages, as all of us are well aware about is a set of detailed instructions for digital computer. But do we have only one programming language? No, there are lots of different programming languages and the number is increasing day by day because new programming languages are emerging as per the requirement of industry. In fact software development is a dynamic field and developers need to constantly be learning new skills to stay relevant.  On the other hand, if we relate it with life then change is the law of life too. In this article, we are giving an overview of three functional programming languages, Clojure, Haskell and Erlang, which accomplish the change in software industry very well.







Clojure: A dialect of LISP

Clojure, created by Rich Hickley, is a dynamic functional programming language whose design is based on LISP programming language. The beauty of Clojure also increases because of the compilers that makes it run on both Java and .Net framework. You can check its official website https://clojure.org/.

Why to love Clojure?

When I worked in this language for the very first time, it looks like a net of parentheses. You can think this is nonsense as like me but once you start working; very soon you are going to fall in love with Clojure. I am saying so just because of the power, consistency and s-expression based syntax of this language. If you are a java lover then It embraces Java very well and it can make use of the entire Java ecosystem for management of the running of the code via the JVM.

Working with Clojure

If you want to work with Clojure as a programming language then you can choose from the following two options:

  • Leiningen: It is an essential tool to create, build and automate Clojure projects. We can download the binary installation from the link http://leiningen-wininstaller. But make sure that you have JDK 1.7 or above on your system and at least 2 GB RAM.
  • Eclipse Plugin: We can use CounterClockwise plugin which is available for Eclipse to carry out Clojure development in Eclipse IDE. Before starting using it, make sure that you have JDK 1.7 or above on your system and Eclipse 4.5(Mars).

Basics of Clojure

In this section, I am going to give a brief overview of this beautiful language. We will start with the general form of statement, as follows, to make you understand about the syntax of Clojure: (+ 2 3)

As I told you earlier about parentheses, you can see the above expression is enclosed in braces too. Before getting into the above expression, I would like to tell you that functions are the main ingredients of every recipe cooked in Clojure. For example, in the above expression the ‘+’ operator acts like a function which is used to add the numbers 2 and 3.

Now, what about (str “Tech” “Alpine”) statement, str is an operator which is used to concatenate two strings which are used as the parameters and in above statement “Tech” and “Alpine” are two strings. We can create a very basic program, as follows, by combining the above statements:

We will start with the very basic example of printing ‘Hello World’.

Listing 1: Sample Clojure example

(ns clojure.techalpine

   (:gen-class))

(defn -main []

   (println “Tech Alpine”))

   (println +2 3)))

It will give the output:

TechAlpine

5

If you want to define perfect language then Clojure is not for you but if you want to build perfect software then it is made for you. Start working with Clojure.







Haskell: Purely functional language

Haskell, functional programming language, is designed for handling symbolic computation. I hope all of you are well aware that functional programming is based on mathematical functions. Even Haskell is named after Haskell Brooks Curry, an American mathematician and logician. You can check its official website https://www.haskell.org/.

What so special about Haskell?

While using Haskell, I feel that the balance of following three flexible and inflexible things make it special:

  • Control Constructs: Functions: – As we know that control constructs defines the order of evaluation and Haskell has functions as its primary control constructs. In Haskell, we can even add a function to another function the way we can add an integer to another integer.
  • Non-strict semantics: – Another thing which makes it so special is its non-strict semantics. Almost all the languages are having strict semantics in which if any sub-expression fails to have a value, the whole expression fails with it.
  • Statically typed: – Haskell is a strictly typed language which means that Haskell compiler is intelligent enough to figure out the type of the variable declared and we need not to explicitly mention the type of variables used.

Working with Haskell

I hope after reading about the things that makes Haskell so special, you really want to work with Haskell. For starting working with Haskell we need to download the available Haskell setup from its official webpage- https://www.haskell.org/downloads. Then we can set up the environment in accordance with our operating system as follows:-

  • For Windows: – We need to download the installer from official website

https:// www.haskell.org/paltform/windows.html.

  • For MAC: – We need to download the installer from official website

https:// www.haskell.org/paltform/mac.html.

  • For Linux: – We need to download the installer from official website

https:// www.haskell.org/paltform/mac.html. After that choose your distribution, run the command sudo apt-get install Haskell-platform and it is ready to use.

Basics of Haskell

In this section, I am going to give a brief overview of this intelligent language. As I have told you earlier that functions are the primary control constructs of this language hence I am giving the example of add function to explain the dynamism of Haskell.

Listing 2: Sample Haskell example 

add : : Integer -> Integer -> Integer

add x y = x + y

main = do

putStrLn “ The addition is “

print(add 1 2)  

The above code is not at all tough to understand. If yes, the following is a one line code of Haskell to print a string:

main = putStrLn “Tech Alpine”

The above one line code will give the output:

TechAlpine

Now, what do you say, is it tough?







Erlang: Functional programming language with runtime environment

Erlang was developed by Ericsson, a Swedish telecom giant, in 1986 with the concept of having integrated support for concurrency and fault tolerance. It is also a functional programming language like Haskell but with its run time environment. It is an open source language since 1998. It is widely referred as Erlang/OTP because OTP consists of its run time environment and it is supported and maintained by OTP product unit at Ericsson. You can check its official website http://www.erlang.org/.

Why to admire Erlang?

If this language is the backbone of messaging apps like WhatsApp, TigerText and Facebook chat then certainly there must be something in this language to admire about. You don’t need to worry about concurrency and fault tolerance once you decided to start working with this wonderful language. “With Erlang you could build a messaging app with many connected users and not worry about how they communicate,” says Chad DePue, CTO of Whisper, an app for anonymous posts that has opted to use the language.

Working with Erlang

I hope after reading about the popularity and features of Erlang, you also want to work with this wonderful language. For starting working with Erlang we need to download the available Erlang setup from its official web page- http://www.erlang.org/downloads. Then we can set up the environment in accordance with our operating system. After finishing the setup, we need to do the configuration of path in our system. Now, open the command prompt and type erl you will be with Erlang. Enjoy coding with Erlang. You can install its plugin on various IDEs too.

Basics of Erlang

In this section, I am going to give a brief overview of this wonderful language. We need to use following different symbols while doing coding in this language:

  • Hyphen(-): – To give the meaning to each statement we will use hyphen symbol. It is mainly used with module as well as import export statement.
  • Dot(.): Each statement would be delimited with the dot(.).
  • Slash(/): – It is used along with the function to define number of parameters which is accepted by the function.
  • Modules: – Every statement in Erlang is divided into modules. You will get more on this in the example we are going to share.
  • Import statement: – To use the functionality of any module in Erlang, we need to use import statement.

Following is an example to understand the basics of Erlang:

Listing 3: Basic Erlang example

-module(TechAlpine).

-export([start/0]).

start() ->

io:fwrite(“TechAlpine\n”).

The above program will give the output:

TechAlpine







End Notes

I hope you have enjoyed this brief discussion over three intelligent, wonderful and beautiful programming languages. Start coding in these languages for great end results. If you come across any difficulty while working with these languages,  or you have any suggestions / feedback please feel free to post them in the

Please follow and like us:
0

Leave a Reply

Your email address will not be published. Required fields are marked *


8 − = 3

============================================= ============================================== Buy TechAlpine Books on Amazon
============================================== ----------------------------------------------------------------

Enjoy this blog? Please spread the word :)

Follow by Email
Facebook
Facebook
Google+
http://techalpine.com/clojure-haskell-and-erlang-a-brief-overview">
LinkedIn