Haskell with Stack

HTTP Client

Dawid Furman

Scala -> Haskell Syntax

Following with the Types

val generateRequestUri : (String, String, String) => String = (host: String, resource: String, id: String) => host +"/"+ resource + "/" + id

->

generateRequestUri :: String -> String -> String -> String
generateRequestUri host resource id = host ++ "/" ++ resource ++ "/" ++ id

Scala -> Haskell Syntax

ADT - Product Type case class Status(code: Int, statusMessage: String) -> data Status = Status { code :: Int,
statusMessage :: String }

Scala -> Haskell Syntax

ADT - Sum Type

sealed trait Result
object Success extends Result
object Failed extends Result
-> data Result = Success | Failed

Scala -> Haskell Syntax

Pattern Matching

def check(r : Result) = r match {
case Failed => "Failed"
case Success => "Success" }
-> r = Success
case r of
Success -> "Success"
Failed -> "Failed"

The Haskell Tool Stack

It`s a dependency ( Hackage and Stackage package repository) and bulid tool (Using Cabal)

stack update

stack new haskell-http

stack build

stack exec haskell-http-exe

The Haskell Tool Stack Stack

Project Structure

Project configuration

1. Add new dependencies to Network.HTTP.Simple and Data.ByteString into Cabal File http-conduit, bytestring

2. Add Language Extension: OverloadedStrings

2. Build the project

3. Run GHCI with the dependencies: stack exec ghci

Let`s Play around

Context computations

Context input -> Context result
inptu -> result

But we are inside Context

so what we need is... Anybody??

FUNCTOR!

Functor

fmap :: Functor f => (a -> b) -> f a -> f b
<=>
(<$>) :: Functor f => (a -> b) -> f a -> f b

¡Implementation!

DIY

Do

IT

Yourself

or

Keep calm and download from: superSimpleHttpHaskellCLI

References

¡Muchas Gracias!

¿Preguntas?

eXtraS for Scala