Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Rubyist's Road to Haskell

A Rubyist's Road to Haskell

In this talk Cies Breijs shares his experiences in learning Haskell as his second language besides Ruby. He will do so from the point of view of a Rubyist: where possible comparing the two languages, available libraries/tools and their communities.

Cies Breijs

January 19, 2015
Tweet

Other Decks in Programming

Transcript

  1. Content 1. My road to Ruby 2. My road to

    Haskell 3. Ruby and Haskell compared 4. Why Haskell makes me happy? 5. Some code
  2. My “next level” web lang short list Haskell (1990) So

    much to learn! Scala (2003) JVM, multi-paradigm was already showing its ugly face Clojure (2007) JVM, still dynamic typing (LISPish) Go (2009) Google owned (mixed blessing), merely a simple C, not FP
  3. Differences Typing discipline Learning curve Creator: one pragmatic dev vs

    many scholars Attitude of community Interpreted vs compiled
  4. Bugs • Expensive • Demotivating (at least annoying) • Make

    refactoring costly • Mess with your estimates
  5. Secondary reasons * Very fast (binaries are optimizable to C++

    speed) * Pure-functional: no place to hide * Very innovative and knowledgeable community * I face the challenges up front * Haskell made me a better Rubyist (programmer) * Learned a lot of new, very useful, concepts * It’s a lot of fun!
  6. Some more code... addSqrs :: Int -> Int -> Int

    addSqrs x y = x^2 + y^2 -- Ruby: def add_sqrs(x, y); x**2 + y**2; end main = putStrLn $ "2^2 + 5^2 = " ++ addSqrs 2 5
  7. Lists [] -- the empty list [1,2,3] -- List of

    Integrals ["foo","bar","baz"] -- List of Strings 1:[2,3] -- [1,2,3], (:) prepends one element 1:2:[] -- [1,2] [1,2] ++ [3,4] -- [1,2,3,4], (++) concatenates [1,2,3] ++ ["foo"] -- ERROR: expects only Integrals [1..] -- [1,2,3,4,5,6,7,8... ad infinitum
  8. Types x :: Int -- x is of type Int

    y :: a -- y is of any type z :: Integral a => a -- z is of any "Integral type class"-type f :: a -> b -- f is a function from a to b g :: a -> b -> c -- g is a function from a to (b -> c) h :: (a -> b) -> [a] -> [b] -- h is a function from (a -> b) -- to ([a] -> [b])
  9. More (from the IDE) main :: IO () main =

    do putStrLn "Hello World!" putStrLn $ show (take 7 squares) putStrLn $ show (take 7 fibs) putStrLn $ show (take 7 (mapAddSqrs [1..])) squares :: [Int] squares = map (^2) [1..] -- Ruby: nums.map{|i| i**2} fibs :: [Int] fibs = 0 : 1 : zipWith (+) fibs (tail fibs) addSqrs :: Int -> Int -> Int addSqrs x y = x^2 + y^2 mapAddSqrs :: [Int] -> [Int] mapAddSqrs = map (\i -> addSqrs i (i+1))
  10. Haskell for the web • Yesod, Snap, Happstack. (Rails) •

    Scotty, Simple, Spock, Wheb, MFlow, and more. (Sinatra) • Haste, unifies client side (JS) and server side. • Other Haskell-to-JS compilers: GHCJS, Fay, PureScript. • All common web-technologies have one-or-more good libraries: Unicode, HTTP, URL, email, JSON, XML, HTML, CSS, SQL (Postgres, MySQL, Sqlite), Memcache, Redis, Mongo, etc.
  11. LambdaCms • Graduation project for two HRO C.S. students •

    Alpha version to be officially released in the following weeks • Sites compile to ~80MB binary (includes: server, all libs, all assets) • 27kB RES memory per thread • 2-10ms responses (involving SQL queries)
  12. Wanna try? Bitemyapp’s “Learn Haskell” overview: https://github.com/bitemyapp/learnhaskell FPComplete’s School of

    Haskell https://www.fpcomplete.com/school FPComplete’s Haskell Center (web IDE) Just click on “Open in IDE” in School of Haskell...