top of page
Writer's pictureThe Tech Platform

Haskell Programming Language



Haskell is a Functional Programming Language that has been specially designed to handle symbolic computation and list processing applications. Functional programming is based on mathematical functions. Besides Haskell, some of the other popular languages that follow Functional Programming paradigm include: Lisp, Python, Erlang, Racket, F#, Clojure, etc.


In conventional programing, instructions are taken as a set of declarations in a specific syntax or format, but in the case of functional programing, all the computation is considered as a combination of separate mathematical functions.


Haskell is a widely used purely functional language. Here, we have listed down a few points that make this language so special over other conventional programing languages such as Java, C, C++, PHP, etc.

  • Functional Language − In conventional programing language, we instruct the compiler a series of tasks which is nothing but telling your computer "what to do" and "how to do?" But in Haskell we will tell our computer "what it is?"

  • Laziness − Haskell is a lazy language. By lazy, we mean that Haskell won't evaluate any expression without any reason. When the evaluation engine finds that an expression needs to be evaluated, then it creates a thunk data structure to collect all the required information for that specific evaluation and a pointer to that thunk data structure. The evaluation engine will start working only when it is required to evaluate that specific expression.

  • Modularity − A Haskell application is nothing but a series of functions. We can say that a Haskell application is a collection of numerous small Haskell applications.

  • Statically Typed − In conventional programing language, we need to define a series of variables along with their type. In contrast, Haskell is a strictly typed language. By the term, Strictly Typed language, we mean the Haskell compiler is intelligent enough to figure out the type of the variable declared, hence we need not explicitly mention the type of the variable used.

  • Maintainability − Haskell applications are modular and hence, it is very easy and cost-effective to maintain them.


History:


The development of Haskell was initiated by a committee that was formed at the conference on Functional Programming Languages and Computer Architecture (FPCA ’87), which took place in Portland, Oregon. The participants of this conference agreed upon the point that a common standard shall be introduced for purely functional languages.


The basic purpose for the formation of this committee was to merge the existing functional languages into a united language, which would be treated as the corner stone for further research and development in the area of functional languages.


The primary version of Haskell, which was called Haskell 1.0, was introduced in the year 1990. The cumulative efforts and hard work of the committee afterwards led towards the development of a range of Haskell versions, namely 1.0, 1.1, 1.2, 1.3, 1.4.


The cessation of the Haskell series occurred in the 1997, which was accompanied with the development of Haskell 98. This development aimed at the introduction of a stable and portable version of the language along with a standard library for the purpose of future developments and teachings. The committee was open to the development of variants and extensions for Haskell 98. This was to be done through the introduction of experimental features in the language.


The Haskell 98 report formally and publically introduce the Haskell 98 language in the year 1999. This was accompanied by a range of developments and the introduction of Haskell 98 Language and Libraries: The Revised Report in January 2003. Since then the language has gone through a series of rapid developments. The present de facto standard is represented by the implementation of Glasgow Haskell Compiler (GHC).


The informal process of development of Haskell Prime during early 2006. This was to be defined as a successor to Haskell 98 standard. This process was intended to introduce a new revision in the definition of the language each year. Haskell 2010, which was the first formal revision, was published in 2010.

It has included a foreign function interface (FFI) in Haskell, eliminated some of the syntax issues, and banned the n plus k patterns. It has also included the extension, called Language-Pragma-Syntax, in the language.


How is Haskell Used?

As a functional programming language, Haskell has benefits like shorter development time, cleaner code, and high reliability. The tight control of side effects also eliminates many unforeseen interactions within a code base. These features are especially of interest to companies who must build software with high fault tolerances, for example, defense industries, finance, telecommunications, and aerospace.


However, Haskell also is used in web startups where functional programming might work better than imperative programming. Apparently Facebook, Google, NVIDIA, and other companies use Haskell to build internal tools used in their software development and IT environments. Even a lawn mower manufacturer in Kansas uses Haskell to build and distribute their mowers. And the New York Times recently used Haskell to build an image processing tool for the 2013 New York Fashion week.



Syntax:

It is a simple example to demonstrate the dynamism of Haskell. Take a look at the following code. All that we need is just one line to print "Hello Word" on the console.

main = putStrLn "Hello World"

Once the Haskell compiler encounters the above piece of code, it promptly yields the following output −

Hello World 


Applications:

  1. Memory safety. Manual memory management in C and C++ often leads to buffer overflows, use-after-free, memory leaks, and other memory-related bugs. This results in security vulnerabilities (see “Observed Examples” for CWE-416: Use After Free). Software written in Haskell is unlikely to exhibit such issues thanks to automatic memory management. Memory safety is a common trait among modern languages, including Java, Python, Go, JavaScript, Rust, and others, and it is absolutely essential for writing secure software.

  2. Garbage collection. There are two ways to achieve memory safety: garbage collection (more common) and static lifetime checking (the Rust way). While garbage collection makes Haskell less suited for real time systems, such as computer games, it is less limiting than lifetime checking, thus facilitating better abstractions and higher developer productivity.

  3. Native code. Unlike Python, Ruby, JavaScript, Lua, and other interpreted languages, Haskell is compiled ahead-of-time, directly to native machine code. The compiler (GHC) is remarkably good at optimization and generating efficient executables. This makes Haskell a great choice for applications that require good performance, such as high-throughput data processing.

  4. Static types. Like Java and unlike JavaScript, Haskell has a type-checker that validates the code during development. This means that many bugs are caught early in the development cycle before the product reaches the users or even the quality assurance department. Furthermore, the developer can study the data model encoded in types to better understand the business domain.

  5. Rich types. Unlike Java or Go, where static types often come off as a nuisance, the type system of Haskell is powerful enough to become a convenience. With support for algebraic data types, parametric polymorphism, class-based (ad-hoc) polymorphism, type families, type equalities, existential quantification, higher-rank polymorphism, kind polymorphism, runtime type inspection, Haskell offers an extremely versatile toolset for writing statically typed programs.

  6. Purity. Haskell’s design is centered around pure functions and immutable data. Over and over, these features have proven essential for writing correct software. Managing global state, mutable data, and side effects is error-prone, and Haskell gives the programmer all the tools to avoid or minimize these sources of complexity.

  7. Laziness. From the very start, Haskell was conceived as a lazy language, and to this day lazy evaluation remains its landmark feature. The idea is to defer computation until the results are needed, and the consequences are ease of refactoring, the ability to define custom control structures, and improved composability.

  8. Concurrency. In many languages, concurrency is a never-ending source of issues, but in Haskell it is fairly straightforward. Green threads, amazing libraries such as async and stm, and ubiquity of pure functions make writing concurrent applications in Haskell a pleasure instead of a headache.

  9. Metaprogramming. Haskell supports the inspection and generation of the program’s abstract syntax tree. This feature is called Template Haskell, and it’s used for compile-time evaluation and to automate boilerplate generation.

  10. Ecosystem. Hackage is a centralized repository of open-source Haskell software, featuring over 14000 packages. Stackage is a curated collection of package versions that guarantees compatibility between libraries, featuring over 2000 well-maintained packages. It is not uncommon to find out that the problem you’re solving has already been solved and shipped as an open-source library.



Advantages:

  • Learning Haskell will change the way you think about programming. (People often find themselves writing Haskell-like code in other languages once they learn Haskell.)

  • Type safety is miles above mainstream languages (null pointer exceptions, anyone?)

  • Type inference means you don't have to worry about types, unless absolutely necessary.

  • It produces high performant executables.

  • Parallelism is almost trivial with the par and pseq combinators

  • The interactive environment (hugs/ghci) allow you to prototype ideas quickly

  • Has a nice supportive community (IRC, mailing lists, etc.)

  • Very expressive and concise syntax

  • GHC is actively being developed and improved, including support for code execution on GPU for that extra kick of high-performance computing


Disadvantages:

  • Immutable values combined with recursion might lead to a reduction in performance

  • In some cases, writing pure functions causes a reduction in the readability of the code

  • Though writing pure functions is easy, combining the same with the rest of the application as well as the I/O operations is tough

  • Writing programs in recursive style in place of using loops for the same can be a daunting task



Sofia Sondh

The Tech Platform


Source: wikipedia

0 comments

Comments


bottom of page