100% tevredenheidsgarantie Direct beschikbaar na betaling Zowel online als in PDF Je zit nergens aan vast
logo-home
Samenvatting Functioneel Programmeren (in Haskell) €5,29   In winkelwagen

Samenvatting

Samenvatting Functioneel Programmeren (in Haskell)

2 beoordelingen
 90 keer bekeken  4 keer verkocht

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

Voorbeeld 3 van de 28  pagina's

  • Ja
  • 26 mei 2021
  • 28
  • 2020/2021
  • Samenvatting
book image

Titel boek:

Auteur(s):

  • Uitgave:
  • ISBN:
  • Druk:
Alle documenten voor dit vak (2)

2  beoordelingen

review-writer-avatar

Door: jelleeichelsheim • 1 week geleden

review-writer-avatar

Door: deen1234pelle • 1 maand geleden

avatar-seller
pactasuntservanda
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]

Voordelen van het kopen van samenvattingen bij Stuvia op een rij:

Verzekerd van kwaliteit door reviews

Verzekerd van kwaliteit door reviews

Stuvia-klanten hebben meer dan 700.000 samenvattingen beoordeeld. Zo weet je zeker dat je de beste documenten koopt!

Snel en makkelijk kopen

Snel en makkelijk kopen

Je betaalt supersnel en eenmalig met iDeal, creditcard of Stuvia-tegoed voor de samenvatting. Zonder lidmaatschap.

Focus op de essentie

Focus op de essentie

Samenvattingen worden geschreven voor en door anderen. Daarom zijn de samenvattingen altijd betrouwbaar en actueel. Zo kom je snel tot de kern!

Veelgestelde vragen

Wat krijg ik als ik dit document koop?

Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.

Tevredenheidsgarantie: hoe werkt dat?

Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.

Van wie koop ik deze samenvatting?

Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper pactasuntservanda. Stuvia faciliteert de betaling aan de verkoper.

Zit ik meteen vast aan een abonnement?

Nee, je koopt alleen deze samenvatting voor €5,29. Je zit daarna nergens aan vast.

Is Stuvia te vertrouwen?

4,6 sterren op Google & Trustpilot (+1000 reviews)

Afgelopen 30 dagen zijn er 77858 samenvattingen verkocht

Opgericht in 2010, al 14 jaar dé plek om samenvattingen te kopen

Start met verkopen
€5,29  4x  verkocht
  • (2)
  Kopen