Haskell Deian Stefan (adopted from my & Edward Yangs CSE242 - - PowerPoint PPT Presentation

haskell
SMART_READER_LITE
LIVE PREVIEW

Haskell Deian Stefan (adopted from my & Edward Yangs CSE242 - - PowerPoint PPT Presentation

Haskell Deian Stefan (adopted from my & Edward Yangs CSE242 slides) Why Haskell? The great ideas [Haskell] Expressive power (say more with less) Pattern matching First-class functions Exception handling Type inference Continuations


slide-1
SLIDE 1

Haskell

Deian Stefan (adopted from my & Edward Yang’s CSE242 slides)

slide-2
SLIDE 2

Why Haskell?

slide-3
SLIDE 3

The great ideas [Haskell]

Expressive power (say more with less) First-class functions Type inference Monads Pattern matching Exception handling Continuations Reliability and reuse Type polymorphism Modules Objects & inheritance Type classes Cross-cutting concerns Memory management Concurrency

slide-4
SLIDE 4

What is Haskell?

a typed, lazy, purely functional language

slide-5
SLIDE 5

Haskell is statically-typed

slide-6
SLIDE 6

Haskell is statically-typed

  • Everything has a type
  • Everything must make sense at compile time

➤ Unlike JavaScript where f(x) with f=undefined will

not complain until you actually evaluate f(x)

  • Is JavaScript typed?

➤ A: yes, B: no

slide-7
SLIDE 7

Why is this cool?

slide-8
SLIDE 8

Why is this cool?

  • Removes whole classes of bugs
  • Address bugs early vs. after they have been triggered

➤ Prevent weird errors from creeping up on you ➤ Important for safety, security, and compositionally

  • Easier to optimize and write faster code

➤ You can remove your typeof checks; compiler can do

fast things. V8 relies on types to makes things fast!

slide-9
SLIDE 9

Haskell is functional

  • This means no“side-effects”?

➤ A: yes, B: no

slide-10
SLIDE 10

Haskell is functional

slide-11
SLIDE 11

Haskell is functional

  • Support for high-order, first-class functions
  • Meaning of programs centered around:

➤ evaluating expressions ➤ not executing instructions

slide-12
SLIDE 12

Haskell is pure

slide-13
SLIDE 13

Haskell is pure

  • Expressions (e.g., functions) don’t have “side effects”

➤ Is JavaScript pure? A: yes, B: no

  • Everything is immutable: mutation is a side-effect!
  • What does it mean for an expression to not have side-

effects?

➤ In scope where x1, …, xn are defined all occurrences

  • f e (where FV(e) = {x1, …, xn}) have the same value
slide-14
SLIDE 14

Why is this cool?

Don’t take it from me, take it from Backus

slide-15
SLIDE 15

Why is this cool?

  • Algebraic laws: equational reasoning & optimizations

➤ Can always replace things that are equal, λ calculus!

  • Easier to think about

➤ e.g., don’t need to worry if x changed after calling f

  • Parallelism

➤ Can evaluate expressions in parallel!

slide-16
SLIDE 16

Haskell is lazy

slide-17
SLIDE 17

Haskell is lazy

  • You don’t evaluate an expression until its result is

absolutely necessary: in contrast to JavaScript

➤ Remember: call-by-name

  • Haskell’s evaluation strategy is called call-by-need

➤ Because of the other properties: you actually only

evaluate an expression once and cache the result

slide-18
SLIDE 18

Why is this cool?

slide-19
SLIDE 19

Why is this cool?

  • Can define your own control structures using functions

➤ E.g., defining if-then-else is much easier in Haskell

can be done naturally; less so in JavaScript; why?

  • Can define infinite data structures

➤ E.g., infinite lists, trees, etc. ➤ Can solve general problem and then project solution

slide-20
SLIDE 20

Haskell is a committee language

slide-21
SLIDE 21

Why is this interesting? [SPJ]

1yr 5yr 10yr 15yr 1,000,000 1 100 10,000

Geeks Practitioners

C , C + + , J a v a S c r i p t , R u b y , . . .

slide-22
SLIDE 22

Why is this interesting? [SPJ]

1yr 5yr 10yr 15yr 1,000,000 1 100 10,000

Geeks Practitioners

Research languages

slide-23
SLIDE 23

Why is this interesting? [SPJ]

1yr 5yr 10yr 15yr 1,000,000 1 100 10,000

Geeks Practitioners

Successful research languages

slide-24
SLIDE 24

Why is this interesting? [SPJ]

1yr 5yr 10yr 15yr 1,000,000 1 100 10,000

Geeks Practitioners

Committee languages

slide-25
SLIDE 25

Why is this interesting? [SPJ]

1yr 5yr 10yr 15yr 1,000,000 1 100 10,000

Geeks Practitioners

Haskell

slide-26
SLIDE 26

intro.hs