• Complain

Mena - Beginning Haskell: a project-based approach

Here you can read online Mena - Beginning Haskell: a project-based approach full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. City: Berkeley;Calif, year: 2014, publisher: Apress, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Mena Beginning Haskell: a project-based approach
  • Book:
    Beginning Haskell: a project-based approach
  • Author:
  • Publisher:
    Apress
  • Genre:
  • Year:
    2014
  • City:
    Berkeley;Calif
  • Rating:
    4 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 80
    • 1
    • 2
    • 3
    • 4
    • 5

Beginning Haskell: a project-based approach: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Beginning Haskell: a project-based approach" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Mena: author's other books


Who wrote Beginning Haskell: a project-based approach? Find out the surname, the name of the author of the book and a list of all author's works by series.

Beginning Haskell: a project-based approach — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Beginning Haskell: a project-based approach" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Part 1
First Steps
Alejandro Serrano Mena 2014
Alejandro Serrano Mena Beginning Haskell 10.1007/978-1-4302-6251-0_1
1. Going Functional
Alejandro Serrano Mena 1
(1)
Madrid, Spain
Welcome to the world of Haskell! Before looking too deeply at the language itself, you will learn about what makes Haskell different from other languages and what benefits come with those differences. Haskell belongs to the family of functional languages , a broad set that includes ML, Lisp, Scala, and Clojure. If you have a background in imperative or object-oriented languages, such as C, C++, or Java, you will be introduced to the new ideas present in functional languages. If you already have experience with functional languages, you will see how other features in Haskell, such as lazy evaluation and type classes, make this language different from any other.
This book requires no previous experience with the functional paradigm. However, some general knowledge about programming (such as the concepts of loops and conditionals) and some minimal practice with the shell or console are assumed.
After introducing Haskell, I will review how to install Haskell on your system, including the EclipseFP development environment that brings Haskell and the Eclipse IDE together. Finally, you will take your first steps with the language in the Glasgow Haskell Compiler (GHC) interpreter, a powerful tool that executes expressions in an interactive way. Throughout the book you will develop parts of a time machine web store; as with many things in life, the best way to learn Haskell is by writing Haskell programs!
Why Haskell?
If you are reading this book, it means you are interested in learning Haskell. But what makes this language special? Its approach to programming can be summarized as follows:
  • Haskell belongs to the family of functional languages.
  • It embodies in its core the concept of purity , separating the code with side effects from the rest of the application.
  • The evaluation model is based on laziness .
  • Types are statically checked by the compiler. Also, Haskell features a type system that is much stronger and expressive than usual.
  • Its approach to polymorphism is based on parametricity (similar to generics in Java and C#) and type classes .
In the rest of this section, you will understand what the terms in this list mean and their implications when using Haskell. Also, you will get a broad view of the entire Haskell ecosystem in a typical distribution: the compiler, the libraries, and the available tools.
Why Pure Functional Programming?
Functional programming is one of the styles, or paradigms , of programming. A programming paradigm is a set of concepts shared by different programming languages. For example, Pascal and C are part of the imperative paradigm, and Java and C++ mix the imperative paradigm with the object-oriented one. The fundamental emphasis of functional programming is the empowerment of functions as first-class citizens . This means functions can be manipulated like any other type of data in a program. A function can be passed as an argument to another function, returned as a result, or assigned to a variable. This ability to treat functions as data allows a higher level of abstraction and therefore more opportunities for reuse.
For example, consider the task of iterating through a data structure, performing some action on each element. In an object-oriented language, the implementer of the structure would have surely followed the iterator pattern, and you as a consumer would write code similar to the following Java code:
Iterator it = listOfThings.iterator();
while (it.hasNext()) {
Element e = it.next();
action(e); // perform the action
}
As you can see, there is a lot of boilerplate code in the example. In Haskell, you would use the map function, which takes as its argument the action to perform on each element. The corresponding code is as follows:
map listOfThings action
The code now is much more concise, and the actual intention of the programmer is explicit from the use of the map function. Furthermore, you prevent any possible issue related to applying the iterator pattern poorly because all the details have been abstracted in a function. Actually, a function such as map is common in functional code, which gives you confidence that any bug in its implementation will be found quickly.
Performing the same task in Java (up to version 7) requires, on the provider side, you to create an interface that contains the function that will perform the operation. Then, on the user side, you need to implement that interface through a class or use an anonymous class. This code will be much longer than the one-line version you saw earlier. In fact, new versions of Java (from version 8 on), C++, and C# (from the release of .NET Framework 3.5) are embracing functional concepts and will allow you to write code similar to the previous line.
In Haskell, a piece of code consists of expressions , which are evaluated in a similar fashion to mathematical expressions. In an imperative language, methods consist of statements that change a global state. This is an important distinction because in an imperative program the same piece of code may have different results depending on the initial state when it is executed. Its important to notice here that elements outside of the program control (known as side effects ), such as input and output, network communication, and randomness, are also part of this global state that may change between executions of the same function.
Expressions in Haskell cannot have side effects by default; these expressions are called pure . A common misunderstanding about functional programming is that it disallows any kind of change to the outer state. This is not true; side effects are possible in Haskell, but the language forces the programmer to separate the pure, side-effect-free parts from the impure ones.
The main benefits of purity are the improved ability to reason about the code and an easier approach for testing the code. You can be sure that the outcome of a pure function depends only on its parameters and that every run with the same inputs will give the same result. This property is called referential transparency , and its the foundation for applying formal verification techniques, as you will see in .
Pure functions are easier to compose because no interference comes to life in their execution. Actually, the evaluation of pure expressions is not dependent on the order in which it is done, so it opens the door to different execution strategies for the same piece of code. This is taken advantage of by the Haskell libraries providing parallel and concurrent execution and has even been used for scheduling code in a GPU in the Accelerate library.
By default, Haskell uses an execution strategy called lazy evaluation . Under laziness, an expression is never evaluated until it is needed for the evaluation of a larger one. Once it has been evaluated, the result is saved for further computation, or its discarded if its not needed in any other running code. This has an obvious benefit because only the minimal amount of computation is performed during program execution, but it also has drawbacks because all the suspended expressions that have not yet been evaluated must be saved in memory. Lazy evaluation is powerful but can become tricky, as you will see in .
Why Strong Static Typing?
Type systems come in various formats in almost all programming languages. A type system is an abstraction that categorizes the values that could appear during execution, tagging them with a so-called type. These types are normally used to restrict the possible set of actions that could be applied to a value. For example, it may allow concatenating two strings but forbid using the division operator between them.
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Beginning Haskell: a project-based approach»

Look at similar books to Beginning Haskell: a project-based approach. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Beginning Haskell: a project-based approach»

Discussion, reviews of the book Beginning Haskell: a project-based approach and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.