3 ms·
This is pretty cool. The Scala version is a little weird. Why do I need a separate Person and Dog class? Can't a dog have a name as well? Why do I need to decla
by wellpast 9y ago
This is pretty cool. The Scala version is a little weird. Why do I need a separate Person and Dog class? Can't a dog have a name as well? Why do I need to declare that upfront or ensure that no other part of code can give a Dog a name? That's the problem with ADTs; there's all this impedance.
The Elm version is much better. Except of course I have to upfront at the method signature declare my property requirements -- while that is also a burden, it is a much lesser burden than having ADT/taxonomy of Person, Dog, etc.
- Bogdanp 9y ago> The Elm version is much better. Except of course I have to upfront at the method signature declare my property requirements -- while that is also a burden, it is a much lesser burden than having ADT/taxonomy of Person, Dog, etc. Elm (and Purescript) should be able to fully infer the type of that function w/o forcing you to declare which fields you want to use up-front.
- wellpast 9y agoHow would it infer: isOld(parseJson(json)) When parseJson may or may not produce an entity with the "age" property?
- Bogdanp 9y agoSorry, I wasn't clear. My point was that you don't have to declare the type of `thing` up front in that example. It would be able to infer that it's a record with an `age` field from the function's definition. In your example, `parseJson` would have to return a record with an age field, otherwise the compiler would complain. Personally, I think that represents a reasonable tradeoff in ease of use for safety.
- simon_o 9y agoI think the Scala version does exactly what you want it to do, but you seem to be confused about something that I can't really pin-point. > Why do I need a separate Person and Dog class? You don't. It's an example. > Can't a dog have a name as well? It can. > Why do I need to declare that upfront or ensure that no other part of code can give a Dog a name? I have trouble understanding the meaning of that sentence.