Jump to content

Haskell/Introduction

From Wikiversity

What is Haskell?

[edit | edit source]

According to the Haskell website, Haskell is a[citation needed]

"polymorphically statically typed, lazy, purely functional language, quite different from most other programming languages. The language is named for Haskell Brooks Curry, whose work in mathematical logic serves as a foundation for functional languages. Haskell is based on the lambda calculus"

What that means

[edit | edit source]

Practically, this means that experience in other, more traditional programming languages, may not be applicable.

Perhaps the most notable difference is that Haskell is a declarative language. This means that instead of the programmer specifying commands for the computer to execute directly, the programmer describes the data and algorithms for the compiler so that it can then tell the computer what to do. Put another way, the programmer says what things are as opposed to how to do them.

Further, the use of strong static typing may require the programmer to think in terms of types to be effective and efficient, which is often not the case in other languages. However, it is worth noting that despite Haskell's strict type system, it does employ type inference, which takes a significant burden off of the programmer.

In addition to the declarative and type-strict aspects of Haskell, it enforces pure functional programming. The primary benefit of pure functional programming is often called referential transparency. This means that any given function will always produce the same output given the same input. This is useful for reducing cognitive load on the programmer, optimization, safety, and simplicity in program design. Further, Haskell functions do not permit side-effects, such as mutating global state or performing IO.

Finally, Haskell is lazy. This is also called call by need. What this means is that functions will only be evaluated as they are needed. Practically, this lets the programmer use infinite data structures with much greater ease than is possible in more traditional evaluation models.

The novice Haskell programmer may initially see the strictness of the type system as a burden and wonder why Haskell uses it at all. The power of the type system allows for more semantic information to be encoded directly into the source code which allows for the compiler to perform more static analysis than it otherwise could. This increase in static analysis means that Haskell can make more guarantees about safety than most languages, perform aggressive optimization, and provide more meaningful error messages to the programmer.