• 08: Docker

    Deploy early and often

    • I want to send this into ‘PROD’ bc running locally is only 1/2 the battle or less
    • After spinning my wheels reading a dozen things. Including using a makefile? oh boy. I needed to reset.
    • Pretty sure I got wrapped up in the ‘what i don’t know’ and lost sight of the “oh yeah”, i’ve done something like that a bit, right?

    Resources

    Follow

  • 07: JSON Payloads

    Returning actual Data in Json

    • Building out some hardcoded users

    • need to supply User before the data

    • don’t forget the = sign

    • We could manually build the encode and decode to/from JSON, but Generics, lets you automatically do things based on the data type

      • adding {-# LANGUAGE DeriveGeneric #-} and import GHC.Generics

      • don’t forget to add instance

      • instance ToJSON User
        instance FromJSON User
        

    Now we are able to see the output of having the generic encoder

    Ok, two modules loaded.
    *Main Lib> import Data.Aeson (encode)
    *Main Lib Data.Aeson> encode bob
    "{\"userName\":\"Bobby Boy\",\"userId\":1}"
    
    • And now with that it looks like Scotty has a function json for use to return a json payload. sweet
        get "/users" $ do
            json allUsers
    

    Resources

    Follow

  • 06: Routed Params

    tackling route params

    • This is really nice that it’s a lot like express
      • We can add route parameters with :xxx in the url, just like Sinatra and express. To read it in our handler, we use the param function. Edit the /hello route to be this
    get "/hello/:name" $ do
        name <- param "name"
        text ("hello " <> name <> "!")
    
    • Tried this, got some errors. realized that Haskell has a ton of ideas about strings. Like Text.

    Text errors

    Text is defined in Data.Text.Internal
              Data.Text.Internal.Lazy.Text
                is defined in Data.Text.Internal.Lazy
    

    Resources

    Follow

  • 05: Routes In Haskell

    Building on our Server API, we want to break down the function called by the route into something more compose-able

    Route Type

    get :: RoutePattern -> ActionM () -> ScottyM ()

    • That’s a get request

    Resources

    docker quick Sean Hess original post

    Follow

  • 04: Practical Haskell

    So, following the book is hard. I don’t really learn well that way. I have just enough knowledge that the first part feels boring and repetitive, but I don’t know what I don’t know, so where do I pick up, chapter 2 or maybe 3? So let’s take this from a real JS perspective.

    Building an API

    • So we know how to get and return json with HTTP requests in Node, how do we do it in Haskell? Ok, now build on that.
    • Make it something relatable.
    1. stack new hs-webapi
    2. Go into /package.yaml and under dependencies add ‘scotty’ and ‘aeson’
    3. Then run stack build
    4. … then wait (forgotten the compile times :eye_roll:) also 67 dependencies. I mean it’s not 867!!!!
    5. ..still waiting.

    Resources

    Follow

  • 03: Lists

    03: Lists

    Handling Lists

    • Before we get started a couple tips for shorthand in Prelude * > GHCi is an interactive Haskell REPL (Read-Eval-Print-Loop) that comes with GHC. At the GHCi prompt, you can evaluate expressions, load Haskell files with :load (:l) (and reload them with :reload (:r)), ask for the type of an expression with :type (:t), and many other things (try :? for a list of commands). * using let in the GHCI
      • Words are are a list of chars

      • In Haskell, lists are a homogenous data structure. It stores several elements of the same type.

      • One of the most basic data types in Haskell

      • List comprehensions?
        • Like set comprehensions, normally used for building more specific sets from a larger general set *
      • List Constructing

        • we should mention type signatures too
        • NOT AN ARRAY
        • ugh, what’s this mean
        • intListLength (x:xs) = 1 + intListLength xs

    Resources

    Follow

  • 02: Tooling

    02: Haskell Tools

    Install

    • stack looks to be the sort of NPM of haskell
    • reproduceable builds,
    • YAML file config. cabal config too

    Command Line

    • stack build and then stack exec hello-world-exe

    • the build will create an executable in the ./stack-work and look there for executables. cool

    • The Setup.hs file is a component of the Cabal build system which stack uses. It’s technically not needed by stack, but it is still considered good practice in the Haskell world to include it. The file we’re using is straight boilerplate:

    • Ok so cabal is a build system that stack uses, but good practice.

    • It is also important to remember that stack is built on top of the Cabal build system. Therefore, an understanding of the moving parts in Cabal are necessary. In Cabal, we have individual packages, each of which contains a single .cabal file. The .cabal file can define 1 or more components: a library, executables, test suites, and benchmarks. It also specifies additional information such as library dependencies, default language pragmas, and so on.

    • So it looks like cabal is the actual package builder and stack is a sort of management tool for haskell language, cabal, and all the other bits/pieces

    • Which ghc is it using?

    • jtomchak@MeowBook:/c/Users/jtomc/Documents/Haskell/hello-world$ stack exec -- which ghc /home/jtomchak/.stack/programs/x86_64-linux/ghc-8.4.3/bin/ghc

    Macros ?

    • {-# LANGUAGE OverloadedStrings #-}
    • not sure what the line means ?
    • appears to be some sort of compile macro ?

    Resources

    * [Install](https://docs.haskellstack.org/en/stable/install_and_upgrade/)
    

    Follow

  • 01: Haskell Quick Rundown

    Episode 1:

    • Learning path github.com/bitemyapp…
    • Functional
      • Two values of functional
        • Functions are first-class, that is, functions are values which can be used in exactly the same ways as any other sort of value.
        • The meaning of Haskell programs is centered around evaluating expressions rather than executing instructions.
    • Pure Haskell expressions are always referentially transparent, that is:
      • No mutation! Everything (variables, data structures…) is immutable.
      • Expressions never have “side effects” (like updating global variables or printing to the screen).
      • Calling the same function with the same arguments results in the same output every time.
    • Lazy
    • Statically Typed
      • Helps clarify thinking and express program structure
      • Serves as a form of documentation
      • Turns run-time errors into compile-time errors
    • Themes
      • Types
      • Abstraction
      • Whole meal programming

    Follow

  • 00: Pilot

    We cover the why of trying to move into Haskell, the format of the show, and what to expect moving forward.

subscribe via RSS