100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4,6 TrustPilot
logo-home
Samenvatting

Samenvatting Functioneel Programmeren (in Haskell)

Beoordeling
3,0
(2)
Verkocht
4
Pagina's
28
Geüpload op
26-05-2021
Geschreven in
2020/2021

Samenvatting van het vak Functioneel Programmeren aan de Universiteit Utrecht, gebaseerd op de hoorcolleges en het boek Programming in Haskell.











Oeps! We kunnen je document nu niet laden. Probeer het nog eens of neem contact op met support.

Documentinformatie

Heel boek samengevat?
Ja
Geüpload op
26 mei 2021
Aantal pagina's
28
Geschreven in
2020/2021
Type
Samenvatting

Voorbeeld van de inhoud

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]

Beoordelingen van geverifieerde kopers

Alle 2 reviews worden weergegeven
1 jaar geleden

1 jaar geleden

3,0

2 beoordelingen

5
0
4
0
3
2
2
0
1
0
Betrouwbare reviews op Stuvia

Alle beoordelingen zijn geschreven door echte Stuvia-gebruikers na geverifieerde aankopen.

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
pactasuntservanda Universiteit Utrecht
Bekijk profiel
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
153
Lid sinds
7 jaar
Aantal volgers
137
Documenten
0
Laatst verkocht
1 maand geleden

3,3

36 beoordelingen

5
7
4
9
3
11
2
4
1
5

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Veelgestelde vragen