Are algebraic datatypes (sealed classes) good for ...
# announcements
u
Are algebraic datatypes (sealed classes) good for api design when you cant tell of all the possible variants just by looking at the funcion? without looking at the type impl details
k
I don't really see a problem here: they're just like normal
open
classes with lots of possible types, just a bit restricted.
u
Yes but you as a consumer dont know about, when compared to maybe monads you see Either you know what to do
k
Well you can always look at the docs or the source, right?
u
Well sure, same as you can use ints for enums .. im just asking questions, not arguing
k
Haha sure, I just don't really get the problem. Of course you need to look at the docs if you want to know about a certain class.
g
I think sealed classes is good option for such api. If you use when as expression compiler will notify you about forgotten cases and even if new class of sealed hierarchy was added later
u
@karelpeeters the problem is imo discoverability, if every sealed class is unique and from call site you dont know its a hierarchy, then intuitively you dont know what to do, but guess when I think about it, enums have the same issue