Skip to content

Instantly share code, notes, and snippets.

@laser
Last active March 17, 2017 18:27
Show Gist options
  • Save laser/610a0ffc1f0bb4aba061 to your computer and use it in GitHub Desktop.
Save laser/610a0ffc1f0bb4aba061 to your computer and use it in GitHub Desktop.
CIS 194 / Winter, 2016 / Outline

CIS 194: Introduction to Haskell

Agenda

  • Why do I like Haskell?
  • Why do I dislike Haskell?
  • What's CIS 194?
  • What's the Plan?
  • Walkthrough of course materials
  • Tracking your progress
  • Participation
  • Development environment setup

Why Do I Like Haskell?

Excellent Type System

Type Inference

main = scotty 3000 $ do
  get "/:word" $ do
    word <- param "word"
    html ("<h1>Hello, " ++ word ++ "</h1>")

Typed Side-Effects

sum :: (Int, Int) -> Int
sum (x,y) = x + y
sum2 :: (Int, Int) -> IO Int
sum2 (x,y) = do
  contents <- readFile "/secret"
  putStr contents
  return (x + y)

Concurrency Story

  • "Lightweight threads" a la Go (Haskell runtime scheduler)
  • Good low-level stuff (forkIO, MVar, etc.)
  • Cool high-level stuff
    • channels
    • software transactional memory
    • thread-safe mutable variables

Laziness (streams for free)

fibonacci :: [Int]
fibonacci = 0 : (next 1 1)
  where next n m = n : (next m (n + m))
*Main> take 10 $ fibonacci
[0,1,1,2,3,5,8,13,21,34]

"Ad Hoc Polymorphism" w/Type Classes

A grouping of methods that operate over some type:

class ToJSON a where
  toJSON :: a -> Value

A type can instantiate these classes by providing an implementation of each method:

data Person { firstName :: Text
            , lastName :: Text }

instance ToJSON Person where
  toJSON (Person f l) = object [ "firstName" .= f
                               , "lastName" .= l ]

Then, we program against the type class instead of an implementation.

createJSONResponse :: ToJSON o => o -> WebServiceResponse ByteString

Instantiate type classes using types you didn't create.

Lots of interesting new things to learn

  • Separating deterministic and nondeterministic code
  • Interesting new abstractions
  • How do we write programs where the state is mostly encapsulated in the call stack?

It's the Latin of FP

Influenced a lot of stuff:

  • Rx (Erik Meijer)
  • Java (generics - Philip Wadler et al.)
  • Swift (protocols)
  • JavaScript (promises chaining)
  • Scala (scalaz, cats)
  • C# (LINQ - Erik Meijer)

Why I Don't Like Haskell

  • Lots of interesting new things to learn
  • Learning curve very steep
  • Poor web-dev library support (relative to say, JavaScript)
  • Poor IDE support (relative to say, Java)
  • Lots of language pragmas
  • Records/fields are stupid (fixed in GHC 8)

Why CIS 194?

  • Original course taught by Brett Yorgey @ U-Penn in Spring 2013
  • According to me and most people on /r/haskell, it's the best option out there
  • Coursework is challenging, illustrative

Things I've Changed

  • Replaced the original IO and Monoids chapters with a single chapter from the Fall '14 version
  • Added a chapter on Quickcheck

What's the Plan?

  • Get together at lunch to talk about the week's lecture and ask questions about homework
  • Presentations?

Walkthrough of Course Materials

  • Go here
  • Lectures
  • Assignments

Tracking Your Progress

Participation

  • Clone the Git repo
  • Create a branch from master using your GitHub username
  • Periodically rebase onto master (let's share tests!)
  • Progress app will build your codes and run tests
  • I'll buy sandwiches each week for individuals who say they've done the homework by the time I wake up on Thursdays

What's Expected of You for Next Week?

  • Finish Chapter 1 homework
  • Read Chapter 2 lecture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment