Slide 1

Slide 1 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 1/37 HASKELL WITH HASKELL WITH STACK STACK HTTP CLIENT HTTP CLIENT Dawid Furman 1

Slide 2

Slide 2 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 2/37 SCALA -> HASKELL SYNTAX SCALA -> HASKELL SYNTAX Following with the Types val generateRequestUri : (String, String, String) => String = (host: String, resource: String, id: String) => host +"/"+ resource + "/" + id

Slide 3

Slide 3 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 3/37 2 . 2

Slide 4

Slide 4 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 4/37 -> 2 . 2

Slide 5

Slide 5 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 5/37 -> generateRequestUri :: String -> String -> String -> String generateRequestUri host resource id = host ++ "/" ++ resource ++ "/" ++ id 2 . 2

Slide 6

Slide 6 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 6/37 SCALA -> HASKELL SYNTAX SCALA -> HASKELL SYNTAX ADT - Product Type case class Status(code: Int, statusMessage: String) -> data Status = Status { code :: Int, statusMessage :: String } 2 . 3

Slide 7

Slide 7 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 7/37 SCALA -> HASKELL SYNTAX SCALA -> HASKELL SYNTAX ADT - Sum Type sealed trait Result object Success extends Result object Failed extends Result -> data Result = Success | Failed 2 . 4

Slide 8

Slide 8 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 8/37 SCALA -> HASKELL SYNTAX 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" 2 . 5

Slide 9

Slide 9 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 9/37 THE HASKELL TOOL THE HASKELL TOOL STACK STACK 3 . 1

Slide 10

Slide 10 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 10/37 THE HASKELL TOOL THE HASKELL TOOL IT`S A DEPENDENCY ( IT`S A DEPENDENCY ( AND AND PACKAGE REPOSITORY) PACKAGE REPOSITORY) AND BULID TOOL (USING AND BULID TOOL (USING ) ) STACK STACK HACKAGE HACKAGE STACKAGE STACKAGE CABAL CABAL 3 . 1

Slide 11

Slide 11 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 11/37 THE HASKELL TOOL THE HASKELL TOOL IT`S A DEPENDENCY ( IT`S A DEPENDENCY ( AND AND PACKAGE REPOSITORY) PACKAGE REPOSITORY) AND BULID TOOL (USING AND BULID TOOL (USING ) ) stack update STACK STACK HACKAGE HACKAGE STACKAGE STACKAGE CABAL CABAL 3 . 1

Slide 12

Slide 12 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 12/37 THE HASKELL TOOL THE HASKELL TOOL IT`S A DEPENDENCY ( IT`S A DEPENDENCY ( AND AND PACKAGE REPOSITORY) PACKAGE REPOSITORY) AND BULID TOOL (USING AND BULID TOOL (USING ) ) stack update stack new haskell-http STACK STACK HACKAGE HACKAGE STACKAGE STACKAGE CABAL CABAL 3 . 1

Slide 13

Slide 13 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 13/37 THE HASKELL TOOL THE HASKELL TOOL IT`S A DEPENDENCY ( IT`S A DEPENDENCY ( AND AND PACKAGE REPOSITORY) PACKAGE REPOSITORY) AND BULID TOOL (USING AND BULID TOOL (USING ) ) stack update stack new haskell-http stack build STACK STACK HACKAGE HACKAGE STACKAGE STACKAGE CABAL CABAL 3 . 1

Slide 14

Slide 14 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 14/37 THE HASKELL TOOL THE HASKELL TOOL IT`S A DEPENDENCY ( IT`S A DEPENDENCY ( AND AND PACKAGE REPOSITORY) PACKAGE REPOSITORY) AND BULID TOOL (USING AND BULID TOOL (USING ) ) stack update stack new haskell-http stack build stack exec haskell-http-exe STACK STACK HACKAGE HACKAGE STACKAGE STACKAGE CABAL CABAL 3 . 1

Slide 15

Slide 15 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 15/37 THE HASKELL TOOL STACK STACK THE HASKELL TOOL STACK STACK PROJECT STRUCTURE PROJECT STRUCTURE ├── app │ └── Main.hs << Executable ├── ChangeLog.md ├── haskell-http.cabal << Cabal (build) configuration ├── LICENSE ├── package.yaml ├── README.md ├── Setup.hs ├── src │ └── Lib.hs << Your`s stuff ├── stack.yaml << Stack (dependency) configuration └── test └── Spec.hs

Slide 16

Slide 16 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 16/37 3 . 3

Slide 17

Slide 17 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 17/37 PROJECT PROJECT CONFIGURATION CONFIGURATION 4 . 1

Slide 18

Slide 18 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 18/37 PROJECT PROJECT CONFIGURATION CONFIGURATION 1. Add new dependencies to and into Cabal File http-conduit, bytestring Network.HTTP.Simple Data.ByteString 4 . 1

Slide 19

Slide 19 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 19/37 PROJECT PROJECT CONFIGURATION CONFIGURATION 1. Add new dependencies to and into Cabal File http-conduit, bytestring 2. Add Language Extension: OverloadedStrings Network.HTTP.Simple Data.ByteString 4 . 1

Slide 20

Slide 20 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 20/37 PROJECT PROJECT CONFIGURATION CONFIGURATION 1. Add new dependencies to and into Cabal File http-conduit, bytestring 2. Add Language Extension: OverloadedStrings 2. Build the project Network.HTTP.Simple Data.ByteString 4 . 1

Slide 21

Slide 21 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 21/37 PROJECT PROJECT CONFIGURATION CONFIGURATION 1. Add new dependencies to and into Cabal File http-conduit, bytestring 2. Add Language Extension: OverloadedStrings 2. Build the project 3. Run GHCI with the dependencies: stack exec ghci Network.HTTP.Simple Data.ByteString 4 . 1

Slide 22

Slide 22 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 22/37 LET`S PLAY AROUND LET`S PLAY AROUND 5 . 1

Slide 23

Slide 23 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 23/37 CONTEXT CONTEXT COMPUTATIONS COMPUTATIONS Context input -> Context result inptu -> result 6 . 1

Slide 24

Slide 24 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 24/37 CONTEXT CONTEXT COMPUTATIONS COMPUTATIONS But we are inside Context Context input -> Context result inptu -> result 6 . 1

Slide 25

Slide 25 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 25/37 CONTEXT CONTEXT COMPUTATIONS COMPUTATIONS But we are inside Context so what we need is... Context input -> Context result inptu -> result 6 . 1

Slide 26

Slide 26 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 26/37 CONTEXT CONTEXT COMPUTATIONS COMPUTATIONS But we are inside Context so what we need is... Anybody?? Context input -> Context result inptu -> result 6 . 1

Slide 27

Slide 27 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 27/37 CONTEXT CONTEXT COMPUTATIONS COMPUTATIONS But we are inside Context so what we need is... Anybody?? FUNCTOR! Context input -> Context result inptu -> result 6 . 1

Slide 28

Slide 28 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 28/37 FUNCTOR FUNCTOR fmap :: Functor f => (a -> b) -> f a -> f b <=> (<$>) :: Functor f => (a -> b) -> f a -> f b 7

Slide 29

Slide 29 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 29/37 ¡IMPLEMENTATION! ¡IMPLEMENTATION! 8 . 1

Slide 30

Slide 30 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 30/37 ¡IMPLEMENTATION! ¡IMPLEMENTATION! DIY 8 . 1

Slide 31

Slide 31 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 31/37 ¡IMPLEMENTATION! ¡IMPLEMENTATION! DIY DO DO 8 . 1

Slide 32

Slide 32 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 32/37 ¡IMPLEMENTATION! ¡IMPLEMENTATION! DIY DO DO IT IT 8 . 1

Slide 33

Slide 33 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 33/37 ¡IMPLEMENTATION! ¡IMPLEMENTATION! DIY DO DO IT IT YOURSELF YOURSELF 8 . 1

Slide 34

Slide 34 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 34/37 ¡IMPLEMENTATION! ¡IMPLEMENTATION! DIY DO DO IT IT YOURSELF YOURSELF or 8 . 1

Slide 35

Slide 35 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 35/37 ¡IMPLEMENTATION! ¡IMPLEMENTATION! DIY DO DO IT IT YOURSELF YOURSELF or Keep calm and download from: superSimpleHttpHaskellCLI 8 . 1

Slide 36

Slide 36 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 36/37 REFERENCES REFERENCES 9

Slide 37

Slide 37 text

2/13/2019 Haskell with Stack https://iot.rindus.de/~dawid/HaskellWithStack/?print-pdf 37/37 ¡MUCHAS GRACIAS! ¡MUCHAS GRACIAS! ¿PREGUNTAS? ¿PREGUNTAS? for Scala eXtraS 10