Skip to content

Instantly share code, notes, and snippets.

@JoelQ
Last active June 14, 2022 21:22
Show Gist options
  • Save JoelQ/98c5c6a17fd82d8ddd932a75eceb4276 to your computer and use it in GitHub Desktop.
Save JoelQ/98c5c6a17fd82d8ddd932a75eceb4276 to your computer and use it in GitHub Desktop.
Short exercises to learn how generic types and type variables work in Elm.

Generic Elm types exercises

A series of exercises to get a feel for how generic types and type variables work in Elm. For each of these, you are given some code that is not compiling. Your task is to get it compiling. You can change the body of the function but not the signature. No cheating with Debug.todo or infinite recursions either 😉

Hint: the more generic your signature, the less you can do in the function body.

@eimfach
Copy link

eimfach commented Sep 15, 2019

Is it okay to change the body to [] or Nothing in case of the first List and Maybe ? :P That was the first thing I came up with

@JoelQ
Copy link
Author

JoelQ commented Sep 16, 2019

@eimfach yes! Those are the sorts of answers these exercises are looking for. In many cases, those are the only implementations that will compile (other than Debug.todo, infinite recursions, and similar implementations that work no matter what the signature is).

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