Hi I’m new to elm. I’m working through a tutorial but some of the syntax is outdated. I’m trying to run a simple elm code with a button that adds an exclamation point. Sorry if this has already been asked. When I compile in react it shows the following:
– SHADOWING ------------------------------------------ 04_Architected_hello.elm
The name model
is first defined here:
30| model =
^^^^^
But then it is defined AGAIN over here:
54| view model =
^^^^^
Think of a more helpful name for one of them and you should be all set!
Note: Linters advise against shadowing, so Elm makes “best practices” the
default. Read https://elm-lang.org/0.19.0/shadowing for more details on this
choice.
– SHADOWING ------------------------------------------ 04_Architected_hello.elm
The name model
is first defined here:
30| model =
^^^^^
But then it is defined AGAIN over here:
43| update model msg =
^^^^^
Think of a more helpful name for one of them and you should be all set!
Note: Linters advise against shadowing, so Elm makes “best practices” the
default. Read https://elm-lang.org/0.19.0/shadowing for more details on this
choice.
My code is below:
module ArchitectedHello exposing (Model, Msg(…), main, model, update, view)
import Browser exposing (sandbox)
import Html exposing (…)
import Html.Attributes exposing (style)
import Html.Events exposing (onClick)
main =
Browser.sandbox
{ init = { text = “” }
, view = view
, update = update
}
– This is what our model should look like
type alias Model =
{ text : String }
– Only need one kind of message
model : Model
model =
{ text = “Hello World” }
type Msg
= Text
– Update function only has to worry about one possible case
update : Msg -> Model -> Model
update msg model =
case msg of
Text ->
{ model | text = model.text ++ “!” }
–View
view : Model -> Html Msg
view model =
div []
[ div [] [ text model.text ]
, button [ onClick Text ] [ text “Add exclamation mark” ]
]