evancz / elm-architecture-tutorial

How to create modular Elm code that scales nicely with your app
https://guide.elm-lang.org/
BSD 3-Clause "New" or "Revised" License
4.17k stars 738 forks source link

JSON example has errors #128

Closed pentaphobe closed 5 years ago

pentaphobe commented 5 years ago

Errors reported in-browser via elm-reactor

All installation was using standard installation on MacOS

-- TYPE MISMATCH ------------------------------------------ examples/06-json.elm

Something is off with the body of the `getRandomCatGif` definition:

107|>  Http.get
108|>    { url = "https://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=cat"
109|>    , expect = Http.expectJson GotGif gifDecoder
110|>    }

This `get` call produces:

    Decoder a -> Http.Request a

But the type annotation on `getRandomCatGif` says it should be:

    Cmd Msg

-- TYPE MISMATCH ------------------------------------------ examples/06-json.elm

The 1st argument to `get` is not what I expect:

107|   Http.get
108|>    { url = "https://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=cat"
109|>    , expect = Http.expectJson GotGif gifDecoder
110|>    }

This argument is a record of type:

    { expect : b, url : String }

But `get` needs the 1st argument to be:

    String

-- TYPE MISMATCH ------------------------------------------ examples/06-json.elm

The 1st argument to `expectJson` is not what I expect:

109|     , expect = Http.expectJson GotGif gifDecoder
                                    ^^^^^^
This `GotGif` value is a:

    Result Http.Error String -> Msg

But `expectJson` needs the 1st argument to be:

    Decoder a

-- TOO MANY ARGS ------------------------------------------ examples/06-json.elm

The `expectJson` function expects 1 argument, but it got 2 instead.

109|     , expect = Http.expectJson GotGif gifDecoder
                    ^^^^^^^^^^^^^^^
Are there any missing commas? Or missing parentheses?