PREV: Conditionals Ninjery
NEXT: Map it like it's hot!
A series of exercises for getting familiar with types and their possible values.
Considerations for the exercises:
- Accuracy: Ensure your answers precisely match the values or types specified. Elm's type system is exact, so details matter.
- Exploration: For the 25th exercise in each section, challenge yourself by creating complex combinations of the types listed. This is a chance to apply what you've learned in a creative way.
- Reflection: After completing the exercises, reflect on any patterns you noticed or any aspects of Elm's type system that were particularly challenging or interesting.
Submissions:
Please write your answers in a .md
file (not a .elm
file as we've usually done). To separate your Elm files from your MD files, you may create a folder outside your src
folder, and call it markdown
-- your submission file will go into this markdown
folder.
Please mark down the content of your solutions using the markdown format. You can take this quick and interactive markdown tutorial to get up to speed with markdown.
Basically, I want you to use markdown to number the questions (and possibly answers) in your solution, and use bold text and/or italicized text to make regions stand out. Use headings where appropriate, too.
I don't have any style guide for this. Feel free to freestyle, but your markdown should make semantic sense (so, maybe think in terms of how you'd do it in HTML).
Instructions: For each of the following Elm values, write down its most specific type.
42
True
3.14
'a'
[1, 2, 3]
"Hello, Elm!"
['a', 'b', 'c']
(True, 'a')
Just "Hello"
Nothing
(4 // 1)
[]
[True, False, True]
Just Nothing
[Just 5, Nothing, Just 10]
[Just 'a', Nothing]
[(1, 'a'), (2, 'b')]
[(True, "Yes"), (False, "No")]
Just (Just 'a')
("Hello", [1, 2, 3])
(42, [True, False], Just 'c')
[(True, 42), (False, 24)]
[Just "Hello", Nothing, Just "World"]
("Elm", Just [False, True], ('a', 42))
- Add your own value here for additional practice.
Instructions: For each of the following Elm types, provide three values that satisfy the type.
Int
Bool
Float
Char
[Int]
String
List Char
(Bool, Char)
Maybe String
List (Bool, Int)
Maybe Int
List a
Maybe a
[Bool]
List (Maybe Int)
List (Int, Char)
Maybe (Maybe Char)
List (Bool, String)
List (Maybe Char)
Maybe [Int]
(String, [Int])
(Int, [Bool], Maybe Char)
Maybe (Maybe Int)
(String, Maybe [Bool], (Char, Int))
- Invent your own type and provide a matching value.
PREV: Conditionals Ninjery
NEXT: Map it like it's hot!