Why Functional? Why Haskell?

813 Words2 Pages

Why Functional? Why Haskell? Or more precisely, why is this discussion centered around some mainstream imperative language? Imperative languages have had a long and colored history, and current popular imperative languages are based on a solid foundation of lessons learned over the last several decade. The domain of imperative languages is mature, and well known. It is precisely this knowledge that tells us why it is difficult to write fault free code in imperative languages. Side effects within a program is when the outcome of a function or procedure is based on something other than the parameters passed to it. This is usually reflective of the program state and can be as simple as a global variable or flag. But this ‘side effect’ renders the function or procedure just a little less deterministic and a little less knowable in operation. Code that is written without side effects is known as ‘pure code’, and most functional languages are for the most part based on pure code. Haskell is considered to be a pure language, but for practical reasons supports both side effects and imperative constructs (encapsulated in Monads). Since most of the code in a Haskell program is pure, there is no concept of program flow or state within this code. This means that statements (or statement blocks) can be re-ordered arbitrarily without impact. It also means that a compiler can be very aggressive about condensing, short-circuiting and otherwise optimizing code within a given statement. To summarize, side effects exist in all useful languages, but are explicitly contained (and discouraged) in functional language, and exhibit fewer related faults. In contrast, side effects are encouraged as a methodology for programming in imperative languages (e... ... middle of paper ... ...of faults in imperative languages, and there is a great deal of evidence showing that faults are also somewhat proportional to the number of lines of code. If our goal is to develop methods to developing code with fewer faults, these characteristics show that functional languages are a solid foundation to build this approach. The easy part of this question is ‘why Haskell’, and can be dismissed quickly. Haskell was chosen as the most mature of the modern functional languages. Although most functional languages are based on pure code, it is necessary reality that useful code requires support for side effects, state and program flow. Haskell has addressed that need and provides support for these capabilities through encapsulation in Monads. By measures of active community and large projects, Haskell is arguably one of the most successful of the functional languages.

More about Why Functional? Why Haskell?

Open Document