0% found this document useful (0 votes)
0 views

Discussion7 Comparative Programming

Haskell is a purely functional programming language that utilizes lazy evaluation, calculating expressions only when necessary, which enhances efficiency and allows manipulation of infinite data structures. It features strong typing and static typing, catching type issues at compile time, and emphasizes higher order functions and currying for modularity and code reuse. These concepts facilitate the creation of generic, declarative functions while avoiding explicit loops.

Uploaded by

Hulda Cau
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Discussion7 Comparative Programming

Haskell is a purely functional programming language that utilizes lazy evaluation, calculating expressions only when necessary, which enhances efficiency and allows manipulation of infinite data structures. It features strong typing and static typing, catching type issues at compile time, and emphasizes higher order functions and currying for modularity and code reuse. These concepts facilitate the creation of generic, declarative functions while avoiding explicit loops.

Uploaded by

Hulda Cau
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Lazy evaluation

Haskell also known as lazy programming language is a programming language that is purely
functional and calculates the expressions only when it is necessary (Hughes, 1989). This
avoids some unnecessary processing. For instance, the ++ function in Haskell stands for list
concatenation. If we have the following expression:

[3,6,7,3*10^89,0] ++ [-1, 9]

It will produce the list [3,6,7,3*10^89,0, -1, 9], without calculating the expression 3*10^89,
saving processing time in this case. As shown from the example above, the main idea of the
Haskell language is based on the evaluation of expressions. The implementation of the
language evaluates (simplifies) the expression passed by the programmer to its normal form.

Haskell is a strongly typed and static language, meaning that every expression has a type
defined at runtime. Any type issues will be caught at compile time, for example, if an integer
parameter is expected and a char type is passed. As a functional language, the primary control
structure is the function; the language is based on the observations of Haskell Curry and his
intellectual descendants making the program one of the best tools used in functional
programming, such as the construction of efficient programs, the ability to model complex
algorithms and ease of maintenance (Hughes, 1989). Additionally, lazy evaluation makes it
possible for functions in Haskell to manipulate ‘infinite’ data structures. On the other hand,
lazy evaluation allows us to construct infinite objects piece by piece as necessary

Higher order functions and currying

Higher order functions and currying are two important concepts that provides modularity and
the reuse of the code as well as the expressivity in functional programming like Haskell and
Standard ML.

The ability of higher order function of receiving other function as argument and/or return a
function as result allow that program are written in abstract and generic ways. Similarly,
since in currying the function that can receive multiple arguments is transformed into a
sequence of function that receive one argument per time making it more flexible and reused
(Kunasaikaran & Iqbal, 2016).

Filter and sum functions are example of higher order function and carrying respectively, as
seen in the example bellow, the code is reused avoiding writing explicit loop.
filter:: (a -> Bool) -> [a] -> [a]

filter p [] = []

filter p (x:xs)

|px = x : filter p xs

| otherwise = filter p xs

While in the add function (example below) allow the composition and efficient reuse of the
code:

add :: Int -> (Int -> Int)

add x = \y -> x + y

addFive = add 5

-- addFive agora é do tipo Int -> Int

-- Exemplo de uso:

result = addFive 10 -- Retorna 15

In summary, higher order functions and currying make it easy to write generic and reused
codes, these functions can easily be combinate making it easy the construction of declarative
functions. By using higher order functions and currying you avoid looping. Currying allows
the partial application of functions making it flexible and more reused.

References

Hughes, J. (1989). Why functional programming matters. The Computer Journal, 32(2), 17–

42. https://doi.org/10.1093/comjnl/32.2.98

Kunasaikaran, J., & Iqbal, A. (2016). A brief overview of functional programming languages.

Computer Science and Information Technology, 6(1).

http://ejcsit.uniten.edu.my/index.php/ejcsit/article/download/97/39

You might also like