3 ms·
I can relate to most points in the article but definitely not #4. I'm a newbie and Elm's ways of declaring types are confusing to me. There are custom types, ty
by retepna 3y ago
I can relate to most points in the article but definitely not #4. I'm a newbie and Elm's ways of declaring types are confusing to me. There are custom types, type aliases, records, extensible records, opaque types, phantom types, wrapper types [1]. However, I still wasn't [2] able to model a list of items with a common base type without having to switch-case through all possible types.
[1]: https://gist.github.com/JoelQ/6b303d9ad450537163b6f8f6cf8a4ed8 https://gist.github.com/JoelQ/6b303d9ad450537163b6f8f6cf8a4e...
[2]: https://ellie-app.com/mQ52TY6k3zZa1 https://ellie-app.com/mQ52TY6k3zZa1
- hombre_fatal 3y agoI don't work much with extensible records myself, but maybe an easier solution is to invert it so the item variants are contained in a field: type Item = { name: String, year: Int, kind: Kind } type Kind = Cd { artist: String } | Book { author: String } | Shoes { size: Float } https://ellie-app.com/mSVCN8dQqX8a1 https://ellie-app.com/mSVCN8dQqX8a1 Consider joining the Slack community: https://elmlang.slack.com https://elmlang.slack.com -- The #beginners channel is a great place to ask these kinds of questions.
- retepna 3y agoThank you, that's indeed a better way to model it!