Slide 1

Slide 1 text

Haskell Pragmatic Functional Programming

Slide 2

Slide 2 text

Nope, we’re busy Not pragmatic dude… Programs
 Complexity

Slide 3

Slide 3 text

“Haskell is the most pragmatic functional programming language”

Slide 4

Slide 4 text

Functional Programming A. Functions (the real ones, aka pure ones) B. Functions as values (higher-order) C. Recursion (the only loop construction)

Slide 5

Slide 5 text

Functional Language A. Support for functional abstractions B. Support for handling side-effects C. Efficient (you don’t pay the abstraction)

Slide 6

Slide 6 text

Abstraction Side-Effects Efficiency Scala Erlang Haskell

Slide 7

Slide 7 text

Abstraction

Slide 8

Slide 8 text

Abstraction 
 Side Effects

Slide 9

Slide 9 text

Abstraction 
 Side Effects Efficiency

Slide 10

Slide 10 text

–Gabriel González “Haskell has effects. The difference is that they’re first- class values and not to-the-side”

Slide 11

Slide 11 text

How on Earth is Haskell not popular?

Slide 12

Slide 12 text

Iron Triangle concise
 fast to write efficient
 (fast to run) easy
 (fast to learn)

Slide 13

Slide 13 text

Recursion

Slide 14

Slide 14 text

• Is more general • Haskell tail recursive functions in constant time • Haskell mutual recursive functions in constant time (Monads!)

Slide 15

Slide 15 text

New types

Slide 16

Slide 16 text

New Types • Wrapper evaporates after compilation newtype PK = PrimaryKey Int

Slide 17

Slide 17 text

Laziness

Slide 18

Slide 18 text

Laziness • Possible to reuse functions foldr = … map = foldr… filter = foldr …

Slide 19

Slide 19 text

Type inference

Slide 20

Slide 20 text

Type inference • Global type inference

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Deferred type errors/Type holes

Slide 24

Slide 24 text

Deferred types • -fdefer-type-errors Type errors are converted to runtime errors (good for ghci sessions) • Type holes put the compiler to work for us main = _

Slide 25

Slide 25 text

Dynamic types

Slide 26

Slide 26 text

Dynamic types

Slide 27

Slide 27 text

Software transactional memory

Slide 28

Slide 28 text

STM Haskell is the best language in the world in which to implement an STM • It was originally 100 lines of code, and even now it’s only about 600 lines of C! • It exploits three properties of the language: purity, immutability and laziness • Haskell retries an STM transaction as needed. Immutability allows it to do this fearlessly, and laziness avoids fully evaluating the transaction • STM is harder in other languages. For instance in Clojure you have to manually implement rollback functionality. https://begriffs.com/posts/2016-04-02-software-transactional-memory.html

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

Higher-kinded types

Slide 31

Slide 31 text

Higher-kinded types class Monad (m :: * -> *) where

Slide 32

Slide 32 text

Polymorphic! Higher-kinded types

Slide 33

Slide 33 text

Polymorphic! Higher-kinded types data T (a :: k) = …

Slide 34

Slide 34 text

Data types type classes (type families)

Slide 35

Slide 35 text

Data types type classes (type families) data family XList a data instance XList Char = XCons Char (XList Char) | XNil data instance XList () = XListUnit Int

Slide 36

Slide 36 text

Much more • Loops fusion • Dependent types • Functional Reactive Programming • Speed!

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

Use Haskell!!!

Slide 40

Slide 40 text

return $