Skip to content

Instantly share code, notes, and snippets.

@mfonism
Last active January 23, 2024 22:33
Show Gist options
  • Save mfonism/24325115f6926612b7ef602b4f538e4a to your computer and use it in GitHub Desktop.
Save mfonism/24325115f6926612b7ef602b4f538e4a to your computer and use it in GitHub Desktop.
Elm Homework for Friends at Hamelin

NEXT: Conditionals Ninjery


🌟 Elm Type Challenge! 🌟

Hey Team,

To sharpen our understanding of Elm's type system, I've prepared some (hopefully) intriguing exercises. I encourage you to refrain from using your REPL or any other tools for evaluation. The real value lies in manually working through these problems and enhancing your intuitive grasp of Elm's types as you do so.

Also, I encourage you to discuss and collaborate with each other. But please try figuring them out individually first. It's a fantastic opportunity to test and expand your Elm expertise.


Task 1: Identify the types of the expressions that follow:

This will test your knowledge of the core datatypes in Elm and reinforce the importance of precise typing in Elm, a strongly typed language.

1. (True, [1, 2, 3])
2. ('a', 3.14)
3. ([False, True], 'b')
4. (4 // 1, ["Elm", "Haskell"])
5. (["Hello", "World"], (True, False))
6. ((4.5, 3 // 2), [True, False, True])
7. ('x', [1 // 1, 2 // 1, 3 // 1])
8. ([3.14, 2.71], "Pi and E")
9. (True, ('a', 42 // 1))
10. ((False, 'z'), [5.5, 6.6])
11. ([1 // 1, 2 // 1], (3.14, "Number Pi"))
12. ('c', (True, [1, 2, 3]))
13. (4.5, ["one", "two", "three"])
14. ((True, 3.14), 'e')
15. (['a', 'b', 'c'], False)
16. ("List", [True, False])
17. (5 // 1, (False, 2.71))
18. (('x', 42 // 1), [3.14, 1.61])
19. ([False, True, False], (7 // 1, 'y'))
20. ((4.5, "Float"), ['a', 'b'])

Task 2: Which of these expressions are NOT well-formed, and WHY?

Challenge yourself by determining which of these expressions will compile, and which won't. For each of them the expressions that won't compile, say why it won't compile.

This task is designed to deepen your understanding of Elm's type constraints and syntactic rules.

1. ([True, 4, 'c'], False)
2. ("hello", [1, 3.14, True])
3. ('ab', [1, 2, 3])
4. (3.14, ['x', "xy"])
5. ((True, [1, "two"]), 3 // 1)
6. (['a', 3, True], "Mixed List")
7. (("String", 4.5), ['a', 3])
8. ([5 // 1, 2.71, "three"], False)
9. (('a', "bc"), (123, [True, "False"]))
10. ((["Elm", 42], True), ('c', 3.14))
11. ("div", "span", "p", "a", "img")

🌈 Goodluck 🌈


NEXT: Conditionals Ninjery

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment