These are the elements used inside Ellie to build an exercise.
If the exercise require The Elm Architecure and tests need to access the Model, it is possible to use exerciseWithTea instead of the simpler exercise. It is the analogue of Browser.element but without flags.
import Exercises exposing (..)
-- Write a function `last` that returns
-- the last element of a list.
--
last : List a -> Maybe a
last xs =
-- Your implementation goes here
Nothing
main : Program Flags (Model ModelExercise) (Msg MsgExercise)
main =
exerciseWithTea
{ tests =
-- Your implementation should pass
-- these tests
\model ->
[ last [ 1, 2, 3, 4 ] == Just 4
, last [ 1 ] == Just 1
, last [] == Nothing
, last [ 'a', 'b', 'c' ] == Just 'c'
]
, init = init
, view = view
, update = update
, subscriptions = subscriptions
}
-- Following the definitions of
-- init, view, update, and subscriptions.Flags are the way to pass details about the exercises to the page.
They can be either loaded from external scripts, like in this example:
(HTML)
<script src="https://elm-exercises.netlify.app/index.js"></script>
<script src="https://elm-exercises.netlify.app/001.js"></script>
<script src="https://elm-exercises.netlify.app/start.js"></script>Or they can be hard coded, like in this example (See ExerciseData for a detailed explanation of the fields):
(JavaScript)
var app = Elm.Main.init({
node: document.getElementById("elm"),
flags: {
index: JSON.stringify([]),
exercise: JSON.stringify(
{ id: 1 // Exercise ID
, title: "" // Title of the exercise
, difficulty: Easy // Easy | Medium | Hard | Undefined
, problem: "" // Details of the problem to be solved
, tests: [] // List of tests
, hints: [] // List of hints
, solutions: [] // List of solutions
, ellie: "" // Ellie ID
}
)
}
});Internal. Exposed to be used in type signatures
Internal. Exposed to be used in type signatures
This record define an exercise.
id A sequencial number. It should be the same as the file name. Numbers from 1 to 99 are reserved to the Ninety-nine Problems, Solved in Elm.ellieId, The id from the Ellie urltitle of the exercise. Keep it concise and explicativedifficulty level of the exerciseproblem, a detailed description of the problemtestshints, a list of suggestions that the user can unhide to help him in the process of finding a solutiondummySolution, A placeholder for the solution. Be sure that the type signature is correct and that it compiles. Use dummy values as returned values. For example if the function return List a, you can return []. If the function return Maybe a you can return Nothing, etc.solutions, a list of possible solutionsThese are the same tests of elm-explorations/test. Refer to that package for the documentation.