Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Resumen

Samenvatting Functioneel Programmeren (in Haskell)

Puntuación
3.0
(2)
Vendido
4
Páginas
28
Subido en
26-05-2021
Escrito en
2020/2021

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

Institución
Grado

Vista previa del contenido

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]

Libro relacionado

Escuela, estudio y materia

Institución
Estudio
Grado

Información del documento

¿Un libro?
Subido en
26 de mayo de 2021
Número de páginas
28
Escrito en
2020/2021
Tipo
RESUMEN

Temas

$6.83
Accede al documento completo:

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF


Documento también disponible en un lote

Reseñas de compradores verificados

Se muestran los 2 comentarios
1 año hace

1 año hace

3.0

2 reseñas

5
0
4
0
3
2
2
0
1
0
Reseñas confiables sobre Stuvia

Todas las reseñas las realizan usuarios reales de Stuvia después de compras verificadas.

Conoce al vendedor

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
pactasuntservanda Universiteit Utrecht
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
157
Miembro desde
8 año
Número de seguidores
137
Documentos
0
Última venta
1 semana hace

3.3

36 reseñas

5
7
4
9
3
11
2
4
1
5

Documentos populares

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes