3 ms·
Shame that "dynamic types" is often conflated with just non-static. My favorite "dynamic" type that is stupid useful has to be numbers in Common Lisp. (I thin
by taeric 4y ago
Shame that "dynamic types" is often conflated with just non-static.
My favorite "dynamic" type that is stupid useful has to be numbers in Common Lisp. (I think most all lisps, actually?) Having it widen to be as big of a number as you need it to be, while you are using it, is stupid useful.
- LAC-Tech 4y agoDoes CL have something akin to schemes "numeric tower"? number -> complex -> real -> rational -> integer. Always idly thought that could work in a statically typed lang and was a feature well worth copying (how many languages REPLs are useless as calculators due to floating point errors!)
- taeric 4y agoThe general idea should be fine. The problem gets in that I have to make a choice up front in many static languages. Something I don't have to do if I give up what exact type of number I am using at the moment.
- masklinn 4y agoThat has nothing to do with dynamic types? Haskell has infinite-precision numbers.
- taeric 4y agoSorta. It is dynamic in that the "type" of the data can literally change as you use it. I don't have to say that an input is rational, and it may only become one after I use it in a way that requires that.
- masklinn 4y agoType inference can do that as well.
- taeric 4y agoSorta. Inference can't tell how big of a numeric type I have to support based on just the static typing. You probably could just call the data statically typed, but with the idea that the concrete type that you are actually dealing with could be any of a few types. Think a function in Java that takes in a Number, but obviously has to have code to work with any actual numeric types. Even more fun, the code could do basic bounds checking to make sure that the result you are working with fits, such that the code starts with an Integer it is working with, but auto moves to Long, etc. And that is where I wish dynamic typing focused more. It isn't that the type of things is not knowable. Clearly they can be known. And it is nice to have parameters constrained to be within a range of expected types. The actual type, though, is dependent on runtime data.