Topic > Why Functional? Why Haskell? - 813

Why Functional? Why Haskell? Or more precisely, why is this discussion centered around a traditional imperative language? Imperative languages ​​have had a long and colorful history, and today's popular imperative languages ​​are built on a solid foundation of lessons learned over the past few decades. The domain of imperative languages ​​is mature and well known. It is precisely this knowledge that explains why it is difficult to write error-free code in imperative languages. Side effects within a program occur when the result of a function or procedure is based on something other than the parameters passed to it. This usually reflects the state of the program and can be as simple as a global variable or flag. But this "side effect" makes the function or procedure a little less deterministic and a little less knowable in operation. Code written without side effects is known as "pure code", and most functional languages ​​are mostly based on pure code. Haskell is considered a pure language, but for practical reasons it 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 instructions (or blocks of instructions) can be reordered arbitrarily without any impact. It also means that a compiler can be very aggressive in condensing, shorting, and otherwise optimizing code within a given instruction. To summarize, side effects exist in all useful languages, but they are explicitly contained (and discouraged) in the functional language and show fewer related defects. In contrast, side effects are encouraged as a methodology for programming in imperative languages ​​(and...... half of the paper ......of defects in imperative languages, and there is a lot of evidence showing that defects are also somewhat proportional to the number of lines of code our goal is to develop ways to develop code with fewer errors, these characteristics show that functional languages ​​are a solid foundation for building this approach. why Haskell". ', and can be quickly dismissed. Haskell was chosen as the most mature of modern functional languages. Although most functional languages ​​are based on pure code, useful code is required to require support for effects collateral, state and program flow has addressed that need and provides support for these features through encapsulation in Monads. In terms of active community and large projects, Haskell is undoubtedly one of the most successful functional languages.