hackersnl
DESCRIPTION
My presentation about Haskell on the NL Hacker News MeetupTRANSCRIPT
![Page 1: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/1.jpg)
Welcome
woensdag 27 januari 2010
![Page 2: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/2.jpg)
HaskellChris Eidhof
woensdag 27 januari 2010
![Page 3: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/3.jpg)
Three things
• Strong types
• Purity
• Larger example
woensdag 27 januari 2010
![Page 4: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/4.jpg)
Strong Types
• As programmers, we do a lot of testing:
• * Unit Testing
• * Debugging
• * Specification
woensdag 27 januari 2010
![Page 5: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/5.jpg)
Strong Types
• Can we automate testing?
woensdag 27 januari 2010
![Page 6: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/6.jpg)
List
• data [a] = [] | a : [a]
Type
Type-parameter
Constructor
Constructor
woensdag 27 januari 2010
![Page 7: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/7.jpg)
List Example
Example: List.hs
woensdag 27 januari 2010
![Page 8: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/8.jpg)
Functions
• reverse :: [a] -> [a]
• reverse [] = []
• reverse (x:xs) = reverse xs ++ [x]
Example: Reverse.hs
Give me a list of a And I’ll return alist of a
Pattern Matching
woensdag 27 januari 2010
![Page 9: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/9.jpg)
Purity
• State = Evil
woensdag 27 januari 2010
![Page 10: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/10.jpg)
Purity
• Same Input
• =
• Same output
Referential
Transparency
woensdag 27 januari 2010
![Page 11: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/11.jpg)
Purity
• No side effects:
• * Variables
• * I/O
• * launchMissiles()
woensdag 27 januari 2010
![Page 12: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/12.jpg)
Example
• sort :: [Int] -> [Int]
How do we know sort doesn’t launch missiles?
woensdag 27 januari 2010
![Page 13: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/13.jpg)
Doing I/O
• putStr :: String -> IO ()
The IO type shows us it’s not pure
woensdag 27 januari 2010
![Page 14: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/14.jpg)
Laziness
• if (x < 10 && x > 5)
• Example: Lazy.hs
woensdag 27 januari 2010
![Page 15: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/15.jpg)
Quickcheck
• Automatic testing of pure code.
Example: Reverse.hs
woensdag 27 januari 2010
![Page 16: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/16.jpg)
Software Transactional
Memory
• Composable transactions
• No deadlocks!
woensdag 27 januari 2010
![Page 17: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/17.jpg)
Fusion
• myFunction = map square . map toInt
• = map (square . toInt)
woensdag 27 januari 2010
![Page 18: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/18.jpg)
Parallel code
• map :: (a -> b) -> [a] -> [b]
• parMap :: (a -> b) -> [a] -> [b]
woensdag 27 januari 2010
![Page 19: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/19.jpg)
Effects
Dangerous SafeUseless
UsefulMost
languages
Haskell
Nirvana
Simon Peyton-Jones, Caging The Effects Monsterwoensdag 27 januari 2010
![Page 20: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/20.jpg)
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
![Page 21: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/21.jpg)
Arc Challenge
• Solution in Arc:
• (defop said req
(aform [onlink "click here" (pr "you said: " (arg _ "foo"))] (input "foo") (submit)))
•
woensdag 27 januari 2010
![Page 22: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/22.jpg)
Arc Challenge
arc = do name <- input link "click here" display $ "you said:" ++ name
See gist: http://gist.github.com/260052
woensdag 27 januari 2010
![Page 23: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/23.jpg)
Arc Challenge (2)
arc2 = do name <- input (x,y) <- input link "click here" display (add x y) display ("you said:" ++ name)
input uses type-inference!
woensdag 27 januari 2010
![Page 24: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/24.jpg)
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
![Page 25: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/25.jpg)
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
![Page 26: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/26.jpg)
Keep in touch
• http://github.com/chriseidhof
• @chriseidhof
woensdag 27 januari 2010
![Page 27: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/27.jpg)
One more thing...
woensdag 27 januari 2010
![Page 28: Hackersnl](https://reader033.vdocuments.us/reader033/viewer/2022060108/5550f49ab4c90501448b467f/html5/thumbnails/28.jpg)
Have fun
woensdag 27 januari 2010