This document provides an introduction and overview of the Haskell programming language. It discusses:
- The speaker's background and an introduction to Simon Peyton Jones, a researcher at Microsoft.
- An overview of what Haskell is - a purely functional, lazy, higher-order, strongly typed general purpose language.
- Why learning Haskell is useful even if you don't use it primarily - it encourages different thinking that can improve programming in any language.
- A brief history of the development of Haskell and how it has evolved over time through various versions.
- Examples of real-world applications of Haskell like text tools, GUI programming, databases, networking, and the tiling window manager xmonad
3. Introduction – who?
• Microsoft Consultant @ Atos
• Microsoft Competence Leader for Atos East NL
• Developer, Team lead, Scrum Master
@tjeerdhans
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. Introduction – what?
• Haskell is a programming language that is
•
•
•
•
•
purely functional
lazy
higher order
strongly typed
general purpose
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.
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. Real world Haskell – xmonad
• xmonad is an X11 tiling window manager written
entirely in Haskell
…
xmo..-wut?! DEMO!
14. Real world Haskell – xmonad
• xmonad is an X11 tiling window manager written
entirely in Haskell
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
26. 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
28. 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)
29. 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!
30. 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
31. 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
32. Simple I/O
getLine :: IO String
putStr :: String -> IO () Main program is an
action of type IO ()
main :: IO ()
Main = putStr “Hello World”
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.