Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Ikechukwunwachukwu/f5b637413523151f30849781e84c4939 to your computer and use it in GitHub Desktop.
Save Ikechukwunwachukwu/f5b637413523151f30849781e84c4939 to your computer and use it in GitHub Desktop.
Elm Homework for Friends at Hamelin

PREV: Conditionals Ninjery


Types and Values Ninjery!

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).

The Questions

Identifying the Type of Given Values

Instructions: For each of the following Elm values, write down its most specific type.

  1. 42
  2. True
  3. 3.14
  4. 'a'
  5. [1, 2, 3]
  6. "Hello, Elm!"
  7. ['a', 'b', 'c']
  8. (True, 'a')
  9. Just "Hello"
  10. Nothing
  11. (4 // 1)
  12. []
  13. [True, False, True]
  14. Just Nothing
  15. [Just 5, Nothing, Just 10]
  16. [Just 'a', Nothing]
  17. [(1, 'a'), (2, 'b')]
  18. [(True, "Yes"), (False, "No")]
  19. Just (Just 'a')
  20. ("Hello", [1, 2, 3])
  21. (42, [True, False], Just 'c')
  22. [(True, 42), (False, 24)]
  23. [Just "Hello", Nothing, Just "World"]
  24. ("Elm", Just [False, True], ('a', 42))
  25. Add your own value here for additional practice.

Providing Values That Satisfy Specified Types

Instructions: For each of the following Elm types, provide three values that satisfy the type.

  1. Int
  2. Bool
  3. Float
  4. Char
  5. [Int]
  6. String
  7. List Char
  8. (Bool, Char)
  9. Maybe String
  10. List (Bool, Int)
  11. Maybe Int
  12. List a
  13. Maybe a
  14. [Bool]
  15. List (Maybe Int)
  16. List (Int, Char)
  17. Maybe (Maybe Char)
  18. List (Bool, String)
  19. List (Maybe Char)
  20. Maybe [Int]
  21. (String, [Int])
  22. (Int, [Bool], Maybe Char)
  23. Maybe (Maybe Int)
  24. (String, Maybe [Bool], (Char, Int))
  25. Invent your own type and provide a matching value.

PREV: Conditionals Ninjery

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