What and Why Haskell ?
Haskell is a modern, standard, functional programming language, named for Haskell Brooks Curry, whose work in mathematical logic serves as a foundation for functional languages.
In particular it is, statically and strongly typed, lazy, purely functional language which is quite different from most other programming languages. Let's understand this in detail...
Purely Functional
C, Java, Pascal, Ada, and so on, are all imperative languages which means that, they consist of a sequence of commands, which are executed strictly one after the other, it focuses on results not the process. Languages like Haskell, Scala, Clojure, Erlang etc... are functional. Functional programming (also called FP) is a way of thinking about software construction by creating pure functions, this is used mainly to avoid shared state, mutable data because object with immutable state gives guarantee and trust for all parties consuming it. So, functional languages emphasize on expressions and declarations rather than execution of statements.
A pure function is a function where the return value is only determined by its input values, without observable side effects. This is how functions in math work: Math.cos(x) will, for the same value of x always return the same result. Computing it does not change x. Pure functions act on their parameters. Impure functions are exactly opposite, they can have hidden inputs or outputs, so impure functions cannot be tested in isolation as they have dependencies.
Lazy (non-strict)
Generally, in programming language theory lazy-evaluation is a strategy which delays the expression evaluation until it's value is required (avoids repeated evaluation), only values needed to achieve side-effects are computed, no need of entire computation. Lazy evaluation allows control structures to be defined normally not as primitives.
While using lazy evaluation, an expression is not evaluated as soon as it gets bound to a variable, but when it is forced to produce the expression's value. That is, a statement such as x = a + b the assignment of the result of an expression to a variable clearly calls for the expression to be evaluated and the result placed in x, but what actually is in x is irrelevant until there is a need for its value via a reference to x in some later expression.
For example, when 5 values are passed to a function, depending on the sequence of conditional expressions, only 2 or 3 may actually be used. In imperative languages, all 3 values will be computed. But in Haskell, only the necessary values are computed as it is lazy and also infinite lists can be implemented.
Infinite lists are used fairly often in certain areas of mathematics, so it can be useful to have the ability to manipulate them. With this, performance increases by avoiding needless calculations and error conditions when evaluating compound expressions. There is another type of evaluation called eager or greedy evaluation, in this an expression is evaluated as soon as it is bound to the variable.
Statically and Strongly Typed
In simple, a language is said to be statically typed if the type of the variable is known at compile-time, in dynamically-typed the type of the variable is known at run-time. With statically typed languages, there is extra initial effort required, when defining variables as type of variables need to be known. This can save time when debugging, because any type errors can be caught earlier on.
Static types are enforced by the variable itself, meaning it cannot be changed and the value that is assigned to it must be of the type dictated by the variable, however there are no much differences between both when coming to development flow.
A strongly-typed language is one in which variables are bound to specific data types, and will result in type errors if types do not match up as expected in the expression — regardless of when type checking occurs. the language's type system makes it strongly typed or weakly typed (loosely typed). A number of different language design decisions have been referred to as evidence of "strong" or "weak" typing. Many of these are more accurately understood as the presence or absence of type safety, memory safety, static type-checking, or dynamic type-checking.
Strong typing generally refers to use of programming language types in order to both capture invariants of the code, ensures its correctness, and definitely exclude certain classes of programming errors. Thus there are many strong typing disciplines used to achieve these goals. But, one can write code in strongly typed or weakly typed style. Some language features make it easy to make the programs more strongly typed.
Here are the list of things that makes Haskell unique from other programming languages :
- Uses immutable data
- Supports parallel programming
- Don't have any side-effects
- It avoids confusing problems, errors in the code
- Clearer and more maintainable code
- Can mimic any mathematical functions
- Elegant, reliable
- Easy to maintain
- High-Level and parallel friendly
Being a functional language, Haskell provides some undeniable benefits that are already actively used in the industry, Haskell can guarantee security and stability to large-scale projects and allows building fault-tolerant systems which is proved by large corporations like Google and Facebook, as well as smaller companies like Riskbook and CentralApp. Popular social networks use Haskell for internal R&D projects. Facebook applies it to fight spam. Haskell lets these corporations provide uninterrupted service to millions of users.
Happy Learning 😊
Comments
Post a Comment