Error in my Code from "Elm In Action" Chapter 4

I’m working my way through the book Elm in Action, and have found myself stuck on one of the code revisions.

While the update at [https://livebook.manning.com/book/elm-in-action/chapter-4/42](https://livebook.manning.com/book/elm-in-action/chapter-4/42) contains intentional errors from the author (which get corrected later in the lesson), I’m getting an unexpected error when I try to save the file.

My code:

  1 module PhotoGroove exposing (main)
  2
  3 import Array exposing (Array)
  4 import Browser
  5 import Html exposing (..)
  6 import Html.Attributes exposing (..)
  7 import Html.Events exposing (onClick)
  8 import Random
  9
 10
 11 urlPrefix : String
 12 urlPrefix =
 13     "http://elm-in-action.com/"
 14
 15
 16 type Msg
 17     = ClickedPhoto String
 18     | GotSelectedIndex Int
 19     | ClickedSize ThumbnailSize
 20     | ClickedSurpriseMe
 21
 22
 23 view : Model -> Html Msg
 24 view model =
 25     div [ class "content" ]
 26         (case model.status of
 27           Loaded photos selectedUrl ->
 28             viewLoaded photos selectedUrl model.chosenSize
 29
 30           Loading ->
 31             []
 32
 33           Errored errorMessage ->
 34             [ text ("Error: " ++ errorMessage) ]
 35         )
 36
 37 viewLoaded : List Photo -> String -> ThumbnailSize -> List (Html Msg)
 38 viewLoaded photos selectedUrl chosenSize =
 39     [ h1 [] [ text "Photo Groove" ]
 40     , button
 41         [ onClick ClickedSurpriseMe ]
 42         [ text "Surprise Me!" ]
 43     , h3 [] [ text "Thumbnail Size:" ] ...

When saving, the error reads `"Unable to parse file /var/folders/fw/4g835n4x0qnc1v9gj7trpd_c0000gp/T/vQgfPJB/317.elm:
39:7 To see a detailed explanation, run elm make on the file.’

Line 39:7 looks like it refers to the h1 in viewLoaded. To my eye, the code is consistent with that in the book. Would really appreciate any pointers on what I’m missing here!

The file you posted is truncated. FYI, if you put the file in https://ellie-app.com/new you can compile it directly from the browser and share it here in case of need.

Thanks for the advice. I’ve posted the code here.

In Ellie, the first error listed on compile is is Line 53, column 5 — looks like it has no issue with Line 37 column 7.

Maybe there’s an issue with my local Vim setup?

The error seems to be in line 45:

(List.map (viewSizeChooser [ Small, Medium, Large ])

should be (( before viewSizeChooser is not closed and is not necessary)

(List.map viewSizeChooser [ Small, Medium, Large ])

I think the compiler / LSP has a hard time with stuff like this as then “strange” nesting comes into place as well (if the parser looks for the closing ) it’ll see wrong indentation next ans IMHO it really struggles with bad indentation).

Overall this is why I tend to try and write as little code as will compile and then check (I’ve enabled check-on-save so I save a lot - elm-format helps a lot too as it is often able to fix strange indentation - but not always)

1 Like

That’s it, thank you so much. :see_no_evil:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.