From c7966bcf24be14d3e2867d25f64a319ae3be36df Mon Sep 17 00:00:00 2001 From: ceddlyburge Date: Mon, 17 Feb 2025 21:29:20 +0000 Subject: [PATCH] Add hints --- concepts/web-applications-1/about.md | 2 + .../concept/paulas-palindromes/.docs/hints.md | 44 +++++++++++++++++++ .../paulas-palindromes/.docs/instructions.md | 4 +- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 exercises/concept/paulas-palindromes/.docs/hints.md diff --git a/concepts/web-applications-1/about.md b/concepts/web-applications-1/about.md index 9b65d4be..f8f5bc2e 100644 --- a/concepts/web-applications-1/about.md +++ b/concepts/web-applications-1/about.md @@ -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 @@ -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 diff --git a/exercises/concept/paulas-palindromes/.docs/hints.md b/exercises/concept/paulas-palindromes/.docs/hints.md new file mode 100644 index 00000000..45a457b1 --- /dev/null +++ b/exercises/concept/paulas-palindromes/.docs/hints.md @@ -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 diff --git a/exercises/concept/paulas-palindromes/.docs/instructions.md b/exercises/concept/paulas-palindromes/.docs/instructions.md index 79bd5164..3d4cb064 100644 --- a/exercises/concept/paulas-palindromes/.docs/instructions.md +++ b/exercises/concept/paulas-palindromes/.docs/instructions.md @@ -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