3. Three things
• Strong types
• Purity
• Larger example
woensdag 27 januari 2010
4. Strong Types
• As programmers, we do a lot of testing:
• * Unit Testing
• * Debugging
• * Specification
woensdag 27 januari 2010
5. Strong Types
• Can we automate testing?
woensdag 27 januari 2010
6. List
Type-parameter
Constructor
• data [a] = [] | a : [a]
Type
Constructor
woensdag 27 januari 2010
7. List Example
Example: List.hs
woensdag 27 januari 2010
8. Functions
Give me a list of a And I’ll return a
list of a
• reverse :: [a] -> [a]
• reverse [] = []
• reverse (x:xs) = reverse xs ++ [x]
Pattern Matching
Example: Reverse.hs
woensdag 27 januari 2010
18. Parallel code
• map :: (a -> b) -> [a] -> [b]
• parMap :: (a -> b) -> [a] -> [b]
woensdag 27 januari 2010
19. Effects
Useful
Most Nirvana
languages
Haskell
Useless
Dangerous Safe
Simon Peyton-Jones, Caging The Effects Monster
woensdag 27 januari 2010
20. Arc Challenge
• Write a program that causes the url said (e.g. http://
localhost:port/said) to produce a page with an input field and
a submit button. When the submit button is pressed, that
should produce a second page with a single link saying "click
here." When that is clicked it should lead to a third page that
says "you said: ..." where ... is whatever the user typed in the
original input field. The third page must only show what the
user actually typed. I.e. the value entered in the input field
must not be passed in the url, or it would be possible to
change the behavior of the final page by editing the url.
woensdag 27 januari 2010
21. Arc Challenge
• Solution in Arc:
• (defop said req
(aform [onlink "click here"
(pr "you said: " (arg _ "foo"))]
(input "foo")
(submit)))
•
woensdag 27 januari 2010
22. Arc Challenge
arc = do name <- input
link "click here"
display $ "you said:" ++ name
See gist: http://gist.github.com/260052
woensdag 27 januari 2010
23. Arc Challenge (2)
input uses type-inference!
arc2 = do name <- input
(x,y) <- input
link "click here"
display (add x y)
display ("you said:" ++ name)
woensdag 27 januari 2010
24. Read more
• Real World Haskell - http://book.realworldhaskell.org/
• Haskell.org - http://haskell.org
• Haskell Café - http://haskell.org/haskellwiki/Mailing_lists
• Planet Haskell - http://planet.haskell.org/
• Haskell reddit - http://haskell.reddit.com
•
woensdag 27 januari 2010
25. Getting Started
• 1. Install the Haskell Platform
• http://hackage.haskell.org/platform/
• 2. Haskell in 10 minutes
• http://haskell.org/haskellwiki/
Learn_Haskell_in_10_minutes
woensdag 27 januari 2010
26. Keep in touch
• http://github.com/chriseidhof
• @chriseidhof
woensdag 27 januari 2010