## Learning Haskell

# Intro

Haskell is a functional programming language. Its roots is the lambda calculus which is a mathematical-computational theory to build algorithms different from the traditional *Turing Machine concept*. In this context, the *functions* in a programming language are closer to what a function is in mathematics, and in Haskell functions are *first-class elements*. Haskell is considered a *pure* functional programing language, going further than what you might found in other language where there are *elements* from functional programming paradigma.

The word purity in functional programming is sometimes also used to mean what is more properly called referential transparency. Referential transparency means that the same function, given the same values to evaluate, will always return the same result in pure functional programming, as they do in math. (From the introduction of the book **Haskell Programming from First Principles**)

## Random Notes about Haskell

**Types and Clases**

- The first task is to understand
**types**in Haskell, so it is needed to understand the concept of type and classes that might be different from others languages (more formal).

*type* in Haskell is a collection of values. It seems that everthing is haskell has a type, so for example, a function that two int numbers has type, (Int, Int) -> Int .

*class* is a collection of type that supports a common set of methods. For example, Int and Float both supports a method that evaluate if two Ints (or two Floats) are equal. This is the Eq. Class.

**Arrays**

Second task is to understand the specific type of array (and more advanced definitions like Repa)

First there are many kind of arrays, in a quite complex forest of options. It seems that the kind of array *Unboxed* is the one similar to C and more suited for numerical operations that require speed. *StorableArray* allows to interchange with C, which also is Unboxed.

It is important to think about what its an array: it is something that associate index to values. In basic arrays index has type Int (to undestand it Ix Class but I think that it something complex also). The manual says for example that:

*the bounds of a 10-element, zero-origin vector with Int indices would be (0,9), while a 100 by 100 1-origin matrix might have the bounds ((1,1),(100,100)), In many other languages, such bounds would be written in a form like 1:100, 1:100, but the present form fits the type system better, since each bound is of the same type as a general index.*

Finally, it seems that internally the ((1,1),(100,100)) are stored in a list of index [(1,1),…,(100,100)]. So internally, the array index 1 corresponds to (1,1), the index 2 corresponds to (1,2) etc…, there is a function named range that helps with it:

The definition of an array has type:

like,

A small piece of code similar to,