3 ms·
This piqued my interest, because that's the same way TDD works for me. And then it starts with "Let's go through an example together. Consider the random type
by mpweiher 7y ago
This piqued my interest, because that's the same way TDD works for me.
And then it starts with "Let's go through an example together. Consider the random type signature that I just made up:"
Hmm...I never have a type signature as a starting point, random or not. I have some sort of requirement, some sort of functionality I want out of the code. Soft fuzzy requirements.
And the types rarely if ever tell me what the function does. Heck, a function that's int x int -> int could be just about anything. How about string -> int? Does it convert the string to an integer or count the vowels?
- golergka 7y ago> Heck, a function that's int x int -> int could be just about anything. How about string -> int? That's because using types like "int" and "string" is not a real, valid use of a good type system. Instead, you'd typically have a function type of `newton -> sqMeter -> pascal`, or `username -> accessLevel`. All these types would be implemented through basic int and string types, but declaring them explicitly with very limited conversions inbetween would actually use type system to verify correctness of your code.
- mpweiher 7y agoSo you're going to not have arithmetic or string manipulation?
- codebje 7y agoYou're probably not going to need a separate function for a binary operator.
- tathougies 7y agoNot really. I may have vector length manipulation and address formatting though. But vector lengths are not integers (or natural for that matter) and an address is certainly not a string. Perhaps you could use these primitives to represent these things but we should not confuse representation with equality.
- AgentOrange1234 7y agoYes so much. An integer can represent all sorts of things, so forever programmers have been using integers to represent all sorts of things. If instead of “int age, int size, int color” you have “age_t age, size_t size, color_t color”, and a type system that helps keep these apart, so much confusion can be avoided...
- golergka 7y agoArithmetic of adding up kilograms and meters together is wrong. Arithmetic of adding up kilograms and kilograms together is automatically inherited when you declare a derived type.
- codebje 7y agoI usually start with types. A signature saying I'm going from a pair of ints to one int doesn't say why I want to do that, I trust that the function name will, but it does help guide me to a function that's more likely correct than one without a type signature. More complex types offer more benefit, as they constrain the set of correct implementations further. Consider just the value of saying Int x Int -> Nat. But mostly I like Haskell's type system for the high degree of confidence it gives me while refactoring. Type Tetris is a side benefit on that, IMO.