|
|
|
|
|
by sold
5089 days ago
|
|
To supplement "it's a matter of how much you put into the type system": This error can be caught if you put units of measure into type system. F# can do this, and addition function will have type int<a> -> int<a> -> int<a> while multiplication int<a> -> int<b> -> int<a * b>; for example, int<m/s> -> int<s> -> int<m> might be a function taking velocity and time, and returing distance. I think Haskell has libraries for this. Similarily, add x y = x - y would be detected if (-) required a group, while (+) worked for monoids only. However, it would be rather hard to create a type system detecting a typo in: quadruple x = 3 * x |
|