3 ms·
I love Peaker's answer. To elaborate with a sort of concrete example of how haskell can help you avoid logic bugs as in your physics simulation example: In cod
by jberryman 15y ago
I love Peaker's answer. To elaborate with a sort of concrete example of how haskell can help you avoid logic bugs as in your physics simulation example:
In code where the types start to to tell you less, e.g. when doing a bunch of number crunching, and you have a signature that looks like:
func :: Int -> Int -> Int -> Int
It's common for the programmer to use a "newtype wrapper" to bring some of the logic into the type system like:
newtype Velocity = Velocity Int
newtype Force = Force Int
newtype Iteration = Iteration Int
Then the type system will catch if you accidentally use the Velocity when what you want is Force, etc.
- gtani 15y agoYeah, there's Dimensional package, and I've seen people using algebraic data types, or (RWH) a Units type http://necrobious.blogspot.com/2009/03/fun-example-of-haskells-newtype.html http://necrobious.blogspot.com/2009/03/fun-example-of-haskel... http://flygdynamikern.blogspot.com/2011/04/announce-dimensional-09.html http://flygdynamikern.blogspot.com/2011/04/announce-dimensio... http://book.realworldhaskell.org/read/data-structures.html#x_xF1 http://book.realworldhaskell.org/read/data-structures.html#x...
- prof_hobart 15y agoMost languages can help you avoid using the wrong one through the use of variable names. The problems you might run into are more (for example) using the wrong algorithm for calculating gravity, adjusting the position of one planet before using it to evaluate its impacts on other planets, failing in collision detection etc. I don't see anything in Haskell that would prevent me from doing any of those.
- SomeOtherGuy 15y ago>Most languages can help you avoid using the wrong one through the use of variable names. That doesn't help at all, are you serious? Cause you genuinely sound like you are trolling. Especially when you say things like "if a language can't prevent every possible bug then there's no poing having it prevent any bugs".