• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Haskell for Scala-ists
 

Haskell for Scala-ists

on

  • 1,453 views

Slides of a talk I gave about Haskell for scalaists.

Slides of a talk I gave about Haskell for scalaists.

Statistics

Views

Total Views
1,453
Views on SlideShare
1,453
Embed Views
0

Actions

Likes
1
Downloads
4
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Haskell for Scala-ists Haskell for Scala-ists Presentation Transcript

  • Haskell for Scala-ists Chris Eidhof
  • Three things • Datatypes • Purity • Laziness
  • List • data [a] = [] | a : [a]
  • List • data [a] = [] | a : [a] Type
  • List Type-parameter • data [a] = [] | a : [a] Type
  • List Type-parameter • data [a] = [] | a : [a] Type Constructor
  • List Type-parameter • data [a] = [] | a : [a] Case distinction Type Constructor
  • List Type-parameter Constructor • data [a] = [] | a : [a] Case distinction Type Constructor
  • Functions • reverse :: [a] -> [a] • reverse [] = [] • reverse (x:xs) = reverse xs ++ [x]
  • Functions Give me a list of a • reverse :: [a] -> [a] • reverse [] = [] • reverse (x:xs) = reverse xs ++ [x]
  • 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]
  • 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
  • Purity • State = Evil
  • Purity • Same Input • = • Same output
  • Purity • Same Input • ntial Refere cy Transp aren = • Same output
  • Purity • No side effects: • * Variables / Mutable state • * I/O • * launchMissiles()
  • Example • sort :: [Int] -> [Int] How do we know sort doesn’t launch missiles?
  • Doing I/O • putStrLn :: String -> IO ()
  • Doing I/O • putStrLn :: String -> IO () The IO type shows us it’s not pure
  • Doing I/O (>>=) :: IO a -> (a -> IO b) -> IO b main = putStrLn "hello! what's your name?" >>= () -> getLine >>= name -> putStrLn ("hello, " ++ name)
  • Doing I/O (>>=) :: IO a -> (a -> IO b) -> IO b main = putStrLn "hello! what's your name?" >>= () -> getLine >>= name -> putStrLn ("hello, " ++ name)
  • Doing I/O main = do putStrLn "hello! what's your name?" name <- getLine putStrLn ("hello, " ++ name)
  • Fusion • myFunction = map square . map toInt
  • Fusion • myFunction = map square . map toInt • = map (square . toInt)
  • Quickcheck • Automatic testing of pure code.
  • Parallel code • map  :: (a -> b) -> [a] -> [b] • parMap :: (a -> b) -> [a] -> [b]
  • Composability • Pure code is easy to compose, it is • * Stateless • * Self-contained
  • Effects Useful Most languages Haskell Useless Dangerous Safe Simon Peyton-Jones, Caging The Effects Monster
  • Effects Useful Most Nirvana languages Haskell Useless Dangerous Safe Simon Peyton-Jones, Caging The Effects Monster
  • Effects Useful Most Nirvana languages Haskell Useless Dangerous Safe Simon Peyton-Jones, Caging The Effects Monster
  • Laziness • if (x < 10 && x > 5)
  • Laziness: Quicksort qsort [] = [] qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs) minimum ls = head (quickSort ls)
  • Laziness: Quicksort qsort [] = [] qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs) minimum ls = head (quickSort ls)
  • 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 •
  • 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
  • Keep in touch • http://github.com/chriseidhof • @chriseidhof