Haskell
Tjeerd Hans Terpstra
Microsoft Consultant
Atos
Agenda
• Introduction
• History of Haskell
• Real world Haskell
• I/O
• Step back
• Project Euler
Introduction – who?

• Microsoft Consultant @ Atos
• Microsoft Competence Leader for Atos East NL
• Developer, Team lead, ...
Introduction – who too?
Simon Peyton Jones
Researcher at Microsoft Research (Cambridge, England)

http://research.microsof...
Introduction – what?
• Haskell is a programming language that is
•
•
•
•
•

purely functional
lazy
higher order
strongly t...
Introduction – why?
• Functional programming will make you think
differently about programming
• Mainstream languages are ...
History of Haskell
History of Haskell
History of Haskell 3
History of Haskell 4
© xkcd http://xkcd.com/1312/

Real world Haskell
Real world Haskell
• Text-based tools
• Imperative input/output programming
• Parsing, transforming data

• GUI programmin...
Real world Haskell – xmonad
• xmonad is an X11 tiling window manager written
entirely in Haskell
…

xmo..-wut?! DEMO!
Real world Haskell – xmonad
• xmonad is an X11 tiling window manager written
entirely in Haskell
Why xmonad?
• Because it's
•
•
•
•
•

A real program
of manageable size
that illustrates many Haskell programming techniqu...
Manageable size
Code
metacity
ion3

Comments

Language

>50000

C

20000

700

C

larswm

6000

130

C

wmii

6000

100

C...
Inside xmonad
Things to notice
• Purity makes the interface explicit

• Takes a stack, and returns a stack; that is all

• Takes a stack...
I/O
Where’s the I/O in xmonad?
• All this pure stuff is nice, but sooner or later we
have to:
• Talk to X11, whose interface i...
Doing I/O
• Idea:

• But: now
might do arbitrary stateful things 
• And what does this do?
• What order are the things pr...
The main idea
A value of type (IO t) is an “action” that,
when performed, may do some input/output
before delivering a res...
A helpful picture
A value of type (IO t) is an “action” that,
when performed, may do some input/output
before delivering a...
Simple I/O

getLine :: IO String
putStr :: String -> IO () Main program is an
action of type IO ()

main :: IO ()
Main = p...
Connecting actions up

Goal:
read a line and then write it back out
Connecting actions up

We have connected two actions to
make a new, bigger action.
Getting two lines

We want to just return (s1,s2)
The return combinator
Taking a step back
The central challenge
The challenge of effects
Project Euler
http://projecteuler.net
Thanks
Haskell @ HAN Arnhem 2013-2014
Haskell @ HAN Arnhem 2013-2014
Haskell @ HAN Arnhem 2013-2014
Haskell @ HAN Arnhem 2013-2014
Haskell @ HAN Arnhem 2013-2014
Haskell @ HAN Arnhem 2013-2014
Haskell @ HAN Arnhem 2013-2014
Haskell @ HAN Arnhem 2013-2014
Upcoming SlideShare
Loading in …5
×

Haskell @ HAN Arnhem 2013-2014

598 views
426 views

Published on

These are cherry-picked slides from Simon Peyton Jones' excellent tutorial on Haskell at http://research.microsoft.com/en-us/um/people/simonpj/papers/haskell-tutorial/index.htm

I prepared these for a guest lecture at the Hogeschool Arnhem-Nijmegen.

If this piqued your interest, please have a look at SPJ's video's at the above link!

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
598
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
8
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • I stole most of the slidesfromSPJ’s excellent ‘A taste of Haskell’ introduction, so a lot of credit goestohim.
  • Examples?Why not obvious? (side effects, purity, laziness)
  • Databases : Haskell Database Connectivity
  • new term: alt-shift-enterLayout modes: alt-spaceKill window: alt-shift-cMove focus: alt-j, alt-kglxgears
  • FFI = Foreignfunction interface
  • Implement ‘insert’ later togetherwith the whole class.
  • How do you guys think you can test Haskell programs?
  • DEMO> import Test.QuickCheck
  • Why might that do arbitrary stateful things?
  • () = unit, lege tuple“Actions” sometimes called “computations”An action is a first class valueEvaluating an action has no effect; performing the action has an effect
  • () = unit, lege tuple“Actions” sometimes called “computations”An action is a first class valueEvaluating an action has no effect; performing the action has an effect
  • Plan ACode contracts, spec#By using parallel concepts (reactive extensions, linq), the need for better control over effects becomes greater (atomic actions)Plan BSelectively allow side effects (monads, e.g. IO)
  • Do Euler 1 andmaybe 2 togetherwith the whole class.
  • Haskell @ HAN Arnhem 2013-2014

    1. 1. Haskell Tjeerd Hans Terpstra Microsoft Consultant Atos
    2. 2. Agenda • Introduction • History of Haskell • Real world Haskell • I/O • Step back • Project Euler
    3. 3. Introduction – who? • Microsoft Consultant @ Atos • Microsoft Competence Leader for Atos East NL • Developer, Team lead, Scrum Master @tjeerdhans
    4. 4. Introduction – who too? Simon Peyton Jones Researcher at Microsoft Research (Cambridge, England) http://research.microsoft.com/en-us/people/simonpj/ • A Taste of Haskell - http://research.microsoft.com/enus/um/people/simonpj/papers/haskell-tutorial/index.htm
    5. 5. Introduction – what? • Haskell is a programming language that is • • • • • purely functional lazy higher order strongly typed general purpose
    6. 6. Introduction – why? • Functional programming will make you think differently about programming • Mainstream languages are all about state • Functional programming is all about values • Whether or not you drink the Haskell whisky, you'll be a better programmer in whatever language you regularly use.
    7. 7. History of Haskell
    8. 8. History of Haskell
    9. 9. History of Haskell 3
    10. 10. History of Haskell 4
    11. 11. © xkcd http://xkcd.com/1312/ Real world Haskell
    12. 12. Real world Haskell • Text-based tools • Imperative input/output programming • Parsing, transforming data • GUI programming • Event driven programming • Hook up events to callback functions in Haskell • Database programming • Network programming • Examples: http://book.realworldhaskell.org/read
    13. 13. Real world Haskell – xmonad • xmonad is an X11 tiling window manager written entirely in Haskell … xmo..-wut?! DEMO!
    14. 14. Real world Haskell – xmonad • xmonad is an X11 tiling window manager written entirely in Haskell
    15. 15. Why xmonad? • Because it's • • • • • A real program of manageable size that illustrates many Haskell programming techniques is open-source software is being actively developed by an active community
    16. 16. Manageable size Code metacity ion3 Comments Language >50000 C 20000 700 C larswm 6000 130 C wmii 6000 100 C dwm 4.2 1500 200 C 500 700 Haskell xmonad 0.2
    17. 17. Inside xmonad
    18. 18. Things to notice • Purity makes the interface explicit • Takes a stack, and returns a stack; that is all • Takes a stack; may modify it; may modify other persistent state; may do I/O
    19. 19. I/O
    20. 20. Where’s the I/O in xmonad? • All this pure stuff is nice, but sooner or later we have to: • Talk to X11, whose interface is not at all pure • Do input/output (other programs)
    21. 21. Doing I/O • Idea: • But: now might do arbitrary stateful things  • And what does this do? • What order are the things printed? • Are they printed at all? Order of evaluation! Laziness!
    22. 22. The main idea A value of type (IO t) is an “action” that, when performed, may do some input/output before delivering a result of type t
    23. 23. A helpful picture A value of type (IO t) is an “action” that, when performed, may do some input/output before delivering a result of type t
    24. 24. Simple I/O getLine :: IO String putStr :: String -> IO () Main program is an action of type IO () main :: IO () Main = putStr “Hello World”
    25. 25. Connecting actions up Goal: read a line and then write it back out
    26. 26. Connecting actions up We have connected two actions to make a new, bigger action.
    27. 27. Getting two lines We want to just return (s1,s2)
    28. 28. The return combinator
    29. 29. Taking a step back The central challenge
    30. 30. The challenge of effects
    31. 31. Project Euler http://projecteuler.net
    32. 32. Thanks

    ×