4 ms·
Making impossible things impossible seems off. Type checking, by name, is just checking types. Akin to units checking. That said, some things may be impossib
by taeric 6y ago
Making impossible things impossible seems off. Type checking, by name, is just checking types. Akin to units checking.
That said, some things may be impossible at a piecemeal, but correct as whole. Easiest is really any system. The parts usually do not stand on their own. A gear without the bike is effectively impossible to use, but still correct, after all.
- cylon13 6y agoMaking incorrect states impossible to represent is exactly what type systems are about. If you're still thinking in terms of something that's basically checking units, I'd recommend experiencing a more advanced type system like Haskell, at least for a few hundred or thousand lines of code. C or Java are terrible examples of what a type system is capable of.
- morelisp 6y agoIt's extremely formalized, but at least for me the foundation I always come back to to try to explain type systems is the taxonomy in chapter 1 of Stepanov and McJones's Elements of Programming[0]. Type systems help ensure your binary data are well-formed value (and your bits are numbers, your numbers are temperatures, etc. up various hierarchies). I find this is more convincing initially for mechanically sympathetic programmers (including myself) than any taxonomy of endofunctors. [0] http://elementsofprogramming.com/ http://elementsofprogramming.com/
- cylon13 6y agoThis is awesome, thanks for the resource!
- wvenable 6y agoPascal has subrange types -- you can declare a type that is 1..10 for example. Statically typed languages could be more strict and have more basic typing features. In most languages, it's not even as good as units checking because you can't say numeric type X is incompatible with numeric type Y (e.g. Celsius and Fahrenheit).
- catlifeonmars 6y agoWhile it’s true that a gear without a bike is not very useful, one could also argue that it’s also effectively impossible to misuse from a perspective of cyclist safety. Anyway the real power of the type system is that it gives you, the designer, the ability to define what is correct and what is not correct by composition. For example, you might define a type, CompleteBicycle, which is used as an argument to a ride() function. In your definition of complete bicycle, you could require a non-null gear property of type Gear. Sure, Gear exists independently in the type system, but you haven’t defined any uses for it, so it (by definition) can’t be used (or misused). Edit: Grammar
- the_af 6y ago> Making impossible things impossible seems off. Type checking, by name, is just checking types. That's the purpose of (static) type checking: to prevent incorrect programs from running. Ideally your types encode your valid programs (with some limitations).
- masklinn 6y ago> Making impossible things impossible seems off. It's the entire purpose of a static type system. All will fail to provide the necessary tools at one point, and many will fail almost immediately, but types are how you encode what is possible, and typechecking is thus what excludes the impossible. > Akin to units checking. And dimensional analysis is how you know you fucked up and your formula is nonsensical before you even apply it.