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

Haskell with Stack

Haskell with Stack

The presentation prepared for Málaga Scala Developers
event: https://www.meetup.com/Malaga-Scala/events/257954372/
WEB version https://iot.rindus.de/~dawid/HaskellWithStack/

Dawid Furman

January 30, 2019
Tweet

Other Decks in Technology

Transcript

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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