Introduction To Haskell

Lecture 7


The Prolific Haskell Community

Using These Slides

Every slide has a secret note.

  • On Chrome: press F12, then click Console
  • On IE: press F12, then click Console
  • On Firefox: Ctrl+Shift+k


Shortcut Keys:

, PgDn, n, j next slide
, PgUp, p, k prev slide
Esc enables ctrl+f globally

Review of Homework 6

Detect whether a password is strong
A
B
C
D

-- Designed by Jamie M. Swogger

import Data.Char
import Data.List

strong x = length x > 14
    && any isLower x
    && any isUpper x
    && any isDigit x




	    

Haskell Wiki

Find everything you need to know about Haskell directly from the official Wiki.

StackOverflow

More than 10,000 questions tagged

IRC

Server: irc.freenode.net

Channel: #haskell

#haskell is one of the top 10 most popular channels on freenode

Reddit /r/Haskell

More than 10,000 subscribers

Hackage

The ultimate collection of Haskell packages

Hackage + Cabal

  • You should use a tool called Cabal
  • Cabal is a command-line tool that installs packages and their dependencies
  • For example, try installing the HTTP library

    cabal install HTTP

Cabal

Common Architecture for Building Applications and Libraries

  • fetches
  • configures
  • compiles
  • installs

*

Cabal Walkthrough

Let's install and use the HTTP package

  1. Refresh the list of packages
  2. Install the HTTP package
  3. Use it!

1. Refresh the list

Download the most recent list of packages


cabal update
	    

2. Install the package

Find any package from Hackage


cabal install HTTP
	    

3. Use

Cabal takes care of installing the package.

The library can now be imported.


import Network.HTTP
	    

Using Network.HTTP

All packages come with documentation on Hackage

Let's take a look at one of the functions in Network.HTTP

simpleHTTP takes in a Request object, and returns an IO Monad

Try it out


Prelude> import Network.HTTP

Prelude Network.HTTP> :t simpleHTTP
simpleHTTP
  :: HStream ty =>
     Request ty -> IO (Network.Stream.Result (Response ty))
	    

Prelude Network.HTTP> let myRequest 
                      = getRequest "http://duckduckgo.com"

Prelude Network.HTTP> simpleHTTP myRequest >>= getResponseBody
"<!DOCTYPE html>..."
	    

>>=


Prelude Network.HTTP> simpleHTTP myRequest >>= getResponseBody
	      

Huh... What's that?



Prelude Network.HTTP> :t (>>=)
(>>=) :: Monad m => m a -> (a -> m b) -> m b
	      

>>= is called the bind operator

MONADS!

Monad

Stay tuned till next time for a peek into Monads

Homework

  1. Fill out this week's form!
  2. Find the point of intersect of two lines using a package from Hackage
  3. If you need help, address the Haskell community (Wiki, IRC, etc)