Re:Ten Years of Git: An Interview with Linus Torvalds
by vilhelm_s on Monday April 06, 2015 @05:06PM
(#9330701)
But perhaps a better type system can still be helpful. E.g. F# supports units of measure, so you can declare 'dollar' as a unit, and write
This way it is at least clear from the types that the numbers are meant to be multiplied, not added.
[ Parent
| on HN ]
Re:Ten Years of Git: An Interview with Linus Torvalds
by S4M on Monday April 06, 2015 @05:12PM
(#9330731)
I never used F#. In your example, would the code:
meal_cost + tax
trigger a compiler exception?
Re:Ten Years of Git: An Interview with Linus Torvalds
by vilhelm_s on Monday April 06, 2015 @05:24PM
(#9330777)
Yes, you get
The type 'float' does not match the type 'float<dollar>'
There is an online typechecker, so one can try out F# without installing it: http://www.tryfsharp.org/Learn/scientific-computing#units-of...
Re:Ten Years of Git: An Interview with Linus Torvalds
by S4M on Monday April 06, 2015 @05:28PM
(#9330798)
And how about:
meal_cost * tax
?This one makes sense in the real world, so I suppose an advanced type system allows the programmer to specify what operations are legit or not across different types.