3 ms·
A strict type system makes sure your program is statically correct, and catches many bugs caused by the programmer. The real world though is dynamic and I prefe
by z3t4 9y ago
A strict type system makes sure your program is statically correct, and catches many bugs caused by the programmer. The real world though is dynamic and I prefer to check all input data at runtime, eg. each function check if what's passed into it is correct. It not only catches a lot of bugs, those caused by the programmer and the ones caused by interacting with the outside word, it also makes the code easier to test. This probably sounds like I'm swearing in church to a Haskel programmer though.
- thinkpad20 9y agoI'm not sure what you mean, or perhaps you have an incorrect understanding of how Haskell works. Of course data is still checked at runtime; for example a parser will check that a string is formatted in valid way, or a lookup in a hash table will check that a key is valid. This is done at runtime as it would be in virtually any language. However there's no way in Haskell (short of low-level type system tricks) to check that a function with an argument of type `Int` actually receives an `Int` when it is called. There's no need to, because it is guaranteed by the type system. The strength of these guarantees, coupled with the ability to define rich, expressive types, are what makes Haskell programs very robust. For example you can represent all possible results of a valid JSON parse: data Value = Object (HashMap Text Value) | Array (Vector Value) | String Text | Number Float | Bool Bool | Null Which variant of this type is actually encountered will not be determined until runtime, so the program is required to respond to the different cases; however a function which takes type `Value` will never need to worry that it doesn't actually receive one of the above variants at runtime.