3 ms·
Only replying partially as I don't want to repeat myself. Ok, then let's just ignore continuations as they are somehow available in both languages although the
by qammm 13y ago
Only replying partially as I don't want to repeat myself.
Ok, then let's just ignore continuations as they are somehow available in both languages although the Scala one feels a bit more officially endorsed to me.
> def upcase(s: String): UppercasedString
Even with that type signature of course the compiler can not check that for input "a" the output will be "A". Your code could have a bug and upcase "a" to "B" (Off-by-one errors are quite common) and your compiler would be perfectly happy. That is the whole point why unit test are more valuable than compiler type checks: checking specific code behavior and not only static types.
- happy_dino 13y agoMake the function from LowercaseLetter to UppercaseLetter type-safe, too. It might not make much sense in this scenario (there is no one-to-one mapping between upper- and lowercase letters anyway), but it is certainly possible to write code where you can have high confidence that it is correct after passing the type checker. This doesn't mean tests are useless of course: It's not "either types or tests", it's more "use manual techniques (tests) where automated approaches (types) are not expressive enough/too cumbersome to use in this special case". Even those the "manual" approach can be automated a bit: By using types to generate appropriate test cases! ... and that's probably my main point: Use computers for things humans are notoriously bad at.