Skip to content

Commit

Permalink
Add hints
Browse files Browse the repository at this point in the history
  • Loading branch information
ceddlyburge committed Feb 17, 2025
1 parent 0805de5 commit c7966bc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 2 additions & 0 deletions concepts/web-applications-1/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type alias Model =

`update` is a function that gets called with a `Msg` when there's a change (like the user clicking a button).
It takes the current `Model` and the `Msg`, and returns a new `Model`.
The `Msg` can be any type, but in any useful application it is always a [custom type][custom-type].

```elm
type Msg
Expand Down Expand Up @@ -78,6 +79,7 @@ init =
```

[record]: https://elm-lang.org/docs/records
[custom-type]: https://guide.elm-lang.org/types/custom_types.html
[elm-guide-text-fields]: https://guide.elm-lang.org/architecture/text_fields
[html-elements]: https://package.elm-lang.org/packages/elm/html/latest/Html
[element-attributes]: https://package.elm-lang.org/packages/elm/html/latest/Html-Attributes
Expand Down
44 changes: 44 additions & 0 deletions exercises/concept/paulas-palindromes/.docs/hints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Hints

## General

- Check out the [Elm Guide][elm-guide], which has a nice worked example that is similar.

## 1. Define the Model type for the application

- The `Model` contains the application's state - all the data that the application needs.
- This application just needs a string to store the text in the Text Box.
- It can be any type, but in any useful application it is always a [record][record].

## 2. Define the Msg type for the application

- The `Msg` type is a defines the messages that are passed to the `update` function, to trigger specific changes in the model.
- This application only needs one change to the model - updating the model when the text in the Text Box changes.
- It can be any type, but in any useful application it is always a [custom type][custom-type].

## 3. Write the update function

- In any useful application the update function will use a `case` statement to pattern match on the `Msg` parameter.
- IN each branch of the case statement it will extract information it needs from the `Msg` parameter and return an updated `Model`
- The `Model` should be a record, and [record update syntax][record-update-syntax] is normally used.

## 4. Write the view function

- The `view` function should probably return a `div` for the root element
- The first child should be an `input`, with a `value` attribute for the current text, and an `nInput` attribute / event with the relevant variant of the `Msg`.
- The second child should probably be another `div` with a `text`child stating whether the text is a palindrome or not.

## 5. Write the init function

- This should simply return a `Model` with sensible default values (probably an empty string).

## 6. Write the main function

- The main function should just called [`Browser.sandbox`][browser-sandbox]
- `Browser.sandbox` requires a [record][record] argument with the `init`, `update` and `view` functions.

[elm-guide]: https://guide.elm-lang.org/architecture/text_fields
[record]: https://elm-lang.org/docs/records
[custom-type]: https://guide.elm-lang.org/types/custom_types.html
[record-update-syntax]: https://elm-lang.org/docs/records#updating-records
[browser-sandbox]: https://package.elm-lang.org/packages/elm/browser/latest/Browser#sandbox
4 changes: 2 additions & 2 deletions exercises/concept/paulas-palindromes/.docs/instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ Inside this root element, there should be an `input` element (the Text Box),and

## 5. Write the init function

The `init` function should return a sensible initial `Model` value .
The `init` function should return a sensible initial `Model` value.

## 6. Write the main function

The `main` function should call [`Browser.sandbox`][browser-sandbox], passing aa record parameter with the `init`, `update` and `view` functions.
The `main` function should call [`Browser.sandbox`][browser-sandbox], passing a record parameter with the `init`, `update` and `view` functions.

[palindrome-crossword-clues]: https://www.theguardian.com/crosswords/crossword-blog/2012/nov/01/cryptic-crosswords-beginners-palindromes
[browser-sandbox]: https://package.elm-lang.org/packages/elm/browser/latest/Browser#sandbox

0 comments on commit c7966bc

Please sign in to comment.