100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.6 TrustPilot
logo-home
Summary

Summary Functional Programming (in Haskell)

Rating
3.0
(2)
Sold
4
Pages
28
Uploaded on
26-05-2021
Written in
2020/2021

Summary of the course Functional Programming at Utrecht University, based on the lectures and the book Programming in Haskell.

Institution
Course










Whoops! We can’t load your doc right now. Try again or contact support.

Connected book

Written for

Institution
Study
Course

Document information

Summarized whole book?
Yes
Uploaded on
May 26, 2021
Number of pages
28
Written in
2020/2021
Type
Summary

Subjects

Content preview

What is functional programming?
Define what something is rather than how to compute it. You can write “functional code” in almost any language.


In general, programming languages in which the base method of computation is changing stored values are called
imperative languages. (Constructed from imperative instructions, that specify precisely how the computation should
proceed.) Functional programming can be viewed as a style of programming in which the basic method of computation is
the application of functions to arguments.


Some distinguishing features:


Recursion instead of iteration

Pattern matching on values

A function is defined by a series of equations and the value is compared with each left side until one “fits”.
Expression instead of statements

Functions as first-class citizens

Function is a mapping of arguments to a result
Functions are high-order, and thus can be used by other functions (example is the map function)
Function can be returned from functions


Using purely functional programming, programs will be easy to reason about because:


Data flow only through function arguments and return values

no hidden data-flow through mutable variables/state
Function call and return as only control flow primitive

no loops, break, continue, goto
(almost) unique types

no inheritance hell
high-level declarative data-structures




The Glasgow Haskell Compiler
In Haskell the Main module — the one containing your main function, is the function that will be invoked when you
execute your compiled program. The function must always be named main . (As long as you do not try to import it from
another module, you could name the file differently. Though, there is no reason to do so and you probably shouldn’t!)




Basic syntax

,Comments

Syntax


!-- comment ordinary comment


{- comment -} nested comment; multiline




Conditionals
< , > , !<= , !>= , !== are the same as in many languages. !/= means not equal.


!|| and !&& are OR and AND.


not is not.


You can use ‘ if condition then expression else expression’, although they are not used a lot. Here, you always need
to use both branches.




Naming requirements
Names of functions and its arguments have to begin with a lower-case letter, which can be followed by lower- and upper-
case letters, digits, underscores and forward single quotes. Some words have special meaning in the language and cannot
be used.




Layout rule
Within a script, each definition at the same level must begin in precisely the same column.


Grouping can be made explicit by using curly parentheses and separating each definition by a semi-colon, but this is
usually not preferable.


You can avoid nested if then else expression with guards (which is considered to be good style).


Be aware: For Haskell, you should not use tabs, but instead (2) spaces.




Types
In Haskell, every expression has a type. A type is a collection of related values.


Haskell is statically typed, which means it forbids executing code with type errors. Every term has a type. Once type is
defined, you’re not able to change it.

, Type Inference is the calculation of the type, when no type is given for an expression (it will “guess” one for you). There is a
clear rule for type inference:




Type declaration
We use the notion v !:: T to mean that v is a value in the type T and say v has type T . With :t / :type in
GHCi you can get the type declaration. For example :t True returns:



True !:: Bool




Basic types

Type Description


Bool logical values, either True or False


Char single characters in Unicode, denoted with single quotes ‘


String sequence of characters, denoted with double quotes “


Int integers with fixed range and thus memory; till


Integer integer with unlimited range


single-precision floating-point numbers, fixed amount of memory; number of digits after the decimal point
Float
depends upon the size of the number (32-bits)


Double double-precision floating-point numbers, take up more space (64-bits)




Lists
Lists are sequences of elements of the same type, and are denoted by squared brackets, e.g.



primeNumbers = [3,5,7,11]
$7.13
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached


Also available in package deal

Reviews from verified buyers

Showing all 2 reviews
1 year ago

1 year ago

3.0

2 reviews

5
0
4
0
3
2
2
0
1
0
Trustworthy reviews on Stuvia

All reviews are made by real Stuvia users after verified purchases.

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
pactasuntservanda Universiteit Utrecht
Follow You need to be logged in order to follow users or courses
Sold
153
Member since
7 year
Number of followers
137
Documents
0
Last sold
1 month ago

3.3

36 reviews

5
7
4
9
3
11
2
4
1
5

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions