2 ms·
This particular bug is also a strong argument for using more advanced type systems, even if you have good test coverage. Yes, it's a great pity that the compil
by jgrahamc 13y ago
This particular bug is also a strong argument for using more advanced type systems, even if you have good test coverage.
Yes, it's a great pity that the compiler didn't say "You're multiplying a time.Duration by a time.Duration and expecting it to be a time.Duration".
- dllthomas 13y agoI'm not sure whether you're serious or not (and I see a few different jokes you could be getting at otherwise), but multiplying time by time should give you time squared, not time again. Unfortunately, even Haskell doesn't catch errors of that type if you want to use the ordinary mathematical operators, because (*) :: Num a => a -> a -> a. In this case, that's not what's going on, though. It's multiplying time by unitless scaling factor, which doesn't present the same problem. However, there's a few ways you can get at the issue with the help of the language, you just have to distinguish between the different units you might be using to represent time - this doesn't really take an advanced type system: the example of having a .milliseconds method is along these lines.
- njs12345 13y agoHave you seen the dimensional library? It's a slightly abusive use of the type system, but will check units at compile time. See e.g. http://code.google.com/p/dimensional/wiki/GMExample http://code.google.com/p/dimensional/wiki/GMExample
- dllthomas 13y agoI think so; I've seen similar things, for sure. Obviously Haskell does have the ability to make this distinction; just (unfortunately) it's somewhat incompatible with the standard prelude, and thus common practice.
- straight_talk 13y agoThe F# compiler does that.
- ghswa 13y agoFor those that are interested, here's a link to the docs: http://msdn.microsoft.com/en-us/library/dd233243.aspx http://msdn.microsoft.com/en-us/library/dd233243.aspx