News for hackers. Stuff that matters.
Re:Can Your Static Type System Handle Linear Algebra? (2014) by moron4hire on Wednesday April 29, 2015 @04:56PM (#9461716)
People keep talking about "you don't want to add meters to feet", but that's exactly the opposite of what you want to do. You want to add inches to yards or furlongs or flea wings, and you want to get it right.

What you don't want to do is add length to weight. The true type of your value is not inches, it's length, and expressing it in inches is a formatting issue.

Re:Can Your Static Type System Handle Linear Algebra? (2014) by ndr on Wednesday April 29, 2015 @05:29PM (#9461938)
You might be interested in http://www.wolfram.com/mathematica/new-in-9/units/ - Wolfram's take on units.
Re:Can Your Static Type System Handle Linear Algebra? (2014) by dllthomas on Wednesday April 29, 2015 @10:25PM (#9462990)
When people say "you don't want to add meters to feet" it's a short-hand for "you don't want to add [a primitive data type representing] meters to [a primitive data type representing] feet [thereby getting a nonsensical result]." Whether "inches" is the "true type" of my value depends on the context - what invariants am I trying to enforce by giving it that type?
Re:Can Your Static Type System Handle Linear Algebra? (2014) by ADRIANFR on Wednesday April 29, 2015 @05:28PM (#9461926)
Also, ideally, you don't want to add length to width, or Hertz to Becquerel (both have [1/sec] unit). This was my humble attempt to address this with a Scala Units library: https://github.com/adrianfr/scalau
Re:Can Your Static Type System Handle Linear Algebra? (2014) by coldtea on Wednesday April 29, 2015 @05:40PM (#9462008)
If you want to find the periphery of something you DO want to add length to width...
Re:Can Your Static Type System Handle Linear Algebra? (2014) by Someone on Wednesday April 29, 2015 @06:07PM (#9462155)
No, you add the lengths of the sides. That's type-safe and generalizes from rectangles with edges parallel to the x and y axes to general polygons:

  perimeter = poly.edges.map(length).sum()
Height and width have (implicit) direction; length doesn't.

But yes, this will get hairy. For convenience, you want the ability to add heights, but that only makes sense in some cases. Two 100m high skyscrapers only make a 200m high skyscraper if you place one on top of the other.

Re:Can Your Static Type System Handle Linear Algebra? (2014) by marvy on Wednesday April 29, 2015 @06:53PM (#9462352)
Or maybe you want to find the height of an average skyscraper so you want to add and then divide. This is going too far maybe. At some point, one has to accept that not all logic bugs are type errors, and not all type errors are common enough in practice to worry about. I have no idea where that point is, but I'm sure it exists.