© Stefania Loredana Nita and Marius Mihailescu 2019
Stefania Loredana Nita and Marius MihailescuHaskell Quick Syntax Referencehttps://doi.org/10.1007/978-1-4842-4507-1_1

1. Functional Programming

Stefania Loredana Nita1  and Marius Mihailescu1
(1)
Bucharest, Romania
 

Functional programming represents a programming paradigm in which the computations are evaluated by mathematical functions. The paradigm avoids changing states and using mutable data.

Every function in Haskell is a function in the purest mathematical sense. I/O operations which generate side-effects are represented in a mathematical way.

This chapter introduces you to the advantages of functional programming and then compares it to object-oriented programming.

The Advantages of Functional Programming

There are several advantages of functional programming, listed here:
  • Free from side effects and bugs: As mentioned, functional programming does not maintain state. Therefore, you will not have side effects. In conclusion, you can write code free from side effects and bugs.

  • Efficiency: Functional programs consist of independent units that are able to run concurrently. This means the efficiency is higher.

  • Lazy evaluation: Functional programming supports lazy evaluation constructs such as lazy lists, lazy maps, and so on.

  • Nested functions: Functional programming supports nested functions.

  • Parallel programming efficiency: As mentioned, there is no mutable state, so there are no state-change issues.

Functional Programming vs. Object-Oriented Programming

Table 1-1 highlights the main differences between functional programming and object-oriented programming (OOP). This gives readers with experience in object-oriented programming a chance to understand what it means to move from an OOP paradigm to functional programming.
Table 1-1.

Functional vs. Object-Oriented Programming

Functional Programming

OOP

Functional programming uses immutable data.

Object-oriented programming uses mutable data.

Functional programming is based on a declarative programming model.

Object-oriented programming is based on an imperative programming model.

The focus is on “what you are doing.”

The focus is on “how you are doing.”

Functional programming supports parallel programming.

Object-oriented programming is not suitable for parallel programming.

Functions do not have side effects.

The methods can produce serious side effects.

Flow control is based on using function invocation and function invocation with recursion.

Flow control is based on loops and conditional statements.

The collection data is iterated using a recursion concept.

Object-oriented programming uses a loop concept to iterate Collection.Data such as the for-each loop in C# or Java.

The execution order of statements is not important.

The execution order of statements is very important.

There is support for “abstraction over data” and “abstraction over behavior.”

There is support only for “abstraction over data.”

Summary

This chapter provided a short introduction to functional programming.

The chapters contained in this book cover the most important aspects and powerful elements (techniques, methods, and algorithms) that a beginner Haskell developer needs to get started with.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.157.190