Re:A Failed Experiment with Python Type Annotations
by klodolph on Tuesday June 11, 2019 @08:36PM
(#20160785)
In Haskell, I usually find the quality of error messages to be much worse without top-level annotations.
Re:A Failed Experiment with Python Type Annotations
by dragonwriter on Tuesday June 11, 2019 @11:44PM
(#20161611)
I agree with that, too. My usual practice with Haskell is leave types off to leverage the information gained from type inference (with the intent of annotating signatures when I'm done), but then tell Haskell what I'm thinking the types should be if things break with impenetrable error messages.
But my coding in Haskell is pretty much personal and toy projects; I like the approach, but it may not be ideal for coding in anger.
Re:A Failed Experiment with Python Type Annotations
by joshuamorton on Wednesday June 12, 2019 @04:11AM
(#20162673)
This is generally true with pytype as well, but questionable whether it's a good thing.
Inferred, loose parameter types are great, because while I think it's good to know the differences between iterator, generator, iterable, sequence, container, and so on, it's difficult, and inference will give you the loosest one. But with return values, the inferred type will be the tighest, in other words your function will return a Dict (or worse, a defaultdict) instead of a Mapping or MutableMapping. You almost always want a Mapping.
The good thing about inference (especially with a REPL) is you can write it without the annotation, and then use the inferred type (in Haskell, I usually find that when I resist the temptation to explicitly annotate types, the actual types are more general than I would have specified.)