3 ms·
Because I might write enum Shape { case Circle(Int32), def area(s: Shape): In32 = match s { Not only I had to write something that the compiler alrea
by pmontra 1y ago
Because I might write
enum Shape {
case Circle(Int32),
def area(s: Shape): In32 = match s {
Not only I had to write something that the compiler already knows, but I typed a compilation error. The second type definition is there only to make developers write it wrong. It does not add any information.
- akkad33 1y agoWhat if you make a typo and instead of `area` you type `areas` the second time? I also don't see how one is more DRY than the other. If anything in the second example you typed `Shape` and `area` a bunch of times, so to me it's less DRY
- ddellacosta 1y ago> The second type definition is there only to make developers write it wrong. Int32 is the type of the return value for the function (https://doc.flix.dev/functions.html https://doc.flix.dev/functions.html), which is distinct information not implied by the type being passed in (Shape), so I dispute this characterization--the fact that this type is the same type as the parameter given to all of Shape's terms is specific to this example. Furthermore I suspect it would immediately be caught by the typechecker regardless. While in a language like Haskell you could define this function without a type definition and its type would be inferred (vs. in Flix, see https://doc.flix.dev/functions.html?highlight=inference#functions https://doc.flix.dev/functions.html?highlight=inference#func...), regardless I will almost always declare the type of top-level functions (or even non-top-level functions) for clarity when reading the code. I think this is useful and important information in any case.
- pmontra 1y ago> Int32 is the type of the return value for the function [...] You are right. That part of my argument is wrong.