Hi.
This is for ELM 0.17.x and the documentation on recursive eliminating recursive type aliases
Issue: the docs show how to avoid the compiler error but they do not show how to unwrap the nested subtype
The example from the docs is:
type alias Comment =
{ message : String
, upvotes : Int
, downvotes : Int
, responses : Responses
}
type Responses = Responses (List Comment)
All that is said re accessing the responses is _"...you only have to do some unwrapping in the cases where you are doing something recursive..."
This leads to, _"OK, but how do I do that?"_ 馃
Below that paragraph is needed an example of unwrapping the responses back to a List Comment.
I have something like this:
unwrapResponses : Responses -> List Comment
unwrapResponses responses =
case responses of
Responses comments -> comments
I'm happy to do a PR, but is this the canonical answer? (It seems a little clumsy.)
Thanks.
Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!
Here is what to expect next, and if anyone wants to comment, keep these things in mind.
When you define a union type with only one case, it's possible to do
unwrapResponses (Responses comments) =
Essentially, you're doing a pattern match in the argument list, and because there's only one you know it cannot fail. You can't use this trick, for example, on a Maybe; you'd use a case analysis exactly as you have above.
Most helpful comment
When you define a union type with only one case, it's possible to do
Essentially, you're doing a pattern match in the argument list, and because there's only one you know it cannot fail. You can't use this trick, for example, on a
Maybe; you'd use a case analysis exactly as you have above.