Date post: | 12-May-2015 |
Category: |
Technology |
Upload: | tjeerd-hans-terpstra |
View: | 319 times |
Download: | 1 times |
HaskellTjeerd Hans TerpstraMicrosoft 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, Scrum Master
@tjeerdhans
Introduction – who too?
• A Taste of Haskell - http://research.microsoft.com/en-us/um/people/simonpj/papers/haskell-tutorial/index.htm
Simon Peyton JonesResearcher at Microsoft Research (Cambridge, England)
http://research.microsoft.com/en-us/people/simonpj/
Introduction – what?
• Haskell is a programming language that is• purely functional• lazy• higher order• strongly typed• general purpose
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.
History of Haskell
History of Haskell
History of Haskell 3
History of Haskell 4
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
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 techniques• is open-source software• is being actively developed by an active community
Manageable size
Code Comments Language
metacity >50000 C
ion3 20000 700 C
larswm 6000 130 C
wmii 6000 100 C
dwm 4.2 1500 200 C
xmonad 0.2 500 700 Haskell
Inside xmonad
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
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 is not at all pure• Do input/output (other programs)
Doing I/O
• Idea:
• But: nowmight do arbitrary stateful things • And what does this do?
• What order are the things printed?• Are they printed at all?
Order of evaluation!
Laziness!
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
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
Simple I/O
getLine :: IO StringputStr :: String -> IO ()
main :: IO ()Main = putStr “Hello World”
Main program is an action of type IO ()
Connecting actions up
Goal:read a line and then write it back out
Connecting actions up
We have connected two actions tomake 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
Thanks