5 ms·
What's wrong with just wrapping and unwrapping values as different types, at the few points you need to do so?
by tome 10y ago
What's wrong with just wrapping and unwrapping values as different types, at the few points you need to do so?
- js8 10y agoNot only it becomes ugly, but it also doesn't help you in all situations. Let's say you have a function in a library that has signature Int32 -> Int32. Then you realize you need to do the same thing, but for Int64. You can't reuse it by wrapping. The above can seem silly, but problems like that are very real for Haskell strings. I mean, from type-purity perspective, this behavior is OK. But from practical perspective (like Python's), it's a bummer. Why you shouldn't be able to reuse existing code just with different type signatures?
- tome 10y ago> Let's say you have a function in a library that has signature Int32 -> Int32. Then you realize you need to do the same thing, but for Int64. You can't reuse it by wrapping. For that we have typeclasses.