Live data from Hacker News

Revenge of the Types

lucumr.pocoo.org

11–20 of 137 posts

Re: Revenge of the Types

#11
Armin didn't address what I belive is the main point of adding type annotations to Python: compiler checkable documentation and as hints to IDE:s. Seen in that perspective, a sucky type system is good enough because it's use isn't to verify program correctness. Personally, I think a standardized format for describing types in docstrings would be 100x better but that's not the way the Python core devs have choosen.

Another argument in favor of types is that it will enable Python to optimize code better. But since Python isn't built for static typing, the CPython bytecode interpreter has no facilities for exploiting the extra information. And even if it had, the V8 Javascript VM proves that you dont need static types to generate optimized code.

Re: Revenge of the Types

#12
post #7

Random question for the type experts out there: is there any language that lets me track the units of my numeric variables? For instance, something like this: float drop(float x0, float duration) { float x = x0; float t = 0; float v = 0; float g = -10; float dt = 0.01; while (t /1000 ); // abbrev for a cast: (float ).001 } Then I want the compiler to check that I'm not mixing up my units. It seems like this would be…

The boost units library does this for C++.

Re: Revenge of the Types

#13
post #7

Random question for the type experts out there: is there any language that lets me track the units of my numeric variables? For instance, something like this: float drop(float x0, float duration) { float x = x0; float t = 0; float v = 0; float g = -10; float dt = 0.01; while (t /1000 ); // abbrev for a cast: (float ).001 } Then I want the compiler to check that I'm not mixing up my units. It seems like this would be…

C++11 has user-defined literals: http://akrzemi1.wordpress.com/2012/08/12/user-defined-litera... http://en.wikipedia.org/wiki/C%2B%2B11#User-defined_literals

Re: Revenge of the Types

#14
post #7

Random question for the type experts out there: is there any language that lets me track the units of my numeric variables? For instance, something like this: float drop(float x0, float duration) { float x = x0; float t = 0; float v = 0; float g = -10; float dt = 0.01; while (t /1000 ); // abbrev for a cast: (float ).001 } Then I want the compiler to check that I'm not mixing up my units. It seems like this would be…

Check out F#'s units of measure. http://msdn.microsoft.com/en-us/library/dd233243.aspx

I've got to confess that I love how the design of MS languages regularly exposes my ignorance towards them.

Edit: removed unrelated Wikipedia article (Unit Type)

Re: Revenge of the Types

#15
post #7

Random question for the type experts out there: is there any language that lets me track the units of my numeric variables? For instance, something like this: float drop(float x0, float duration) { float x = x0; float t = 0; float v = 0; float g = -10; float dt = 0.01; while (t /1000 ); // abbrev for a cast: (float ).001 } Then I want the compiler to check that I'm not mixing up my units. It seems like this would be…

Value classes in Scala.

Re: Revenge of the Types

#16
post #14

Earlier quoted context omitted.

Check out F#'s units of measure. http://msdn.microsoft.com/en-us/library/dd233243.aspx

I've got to confess that I love how the design of MS languages regularly exposes my ignorance towards them. Edit: removed unrelated Wikipedia article (Unit Type)

Unit type is completely different concept in the functional languages. It does not track units and measures.

Re: Revenge of the Types

#17
post #14

Earlier quoted context omitted.

I've got to confess that I love how the design of MS languages regularly exposes my ignorance towards them. Edit: removed unrelated Wikipedia article (Unit Type)

Unit type is completely different concept in the functional languages. It does not track units and measures.

Oh my, thanks for the heads-up I guess it's too late to post on HN. Time to go to bed :)

Re: Revenge of the Types

#18
Hrm. I think this article does a great job of explaining weird inconsistencies in Python's current type system, but I think it does a somewhat less good job of demonstrating that adding annotations is actively harmful. What would be some examples of situations where inconsistencies in the type system made annotations problematic in practice? Are those situations compelling enough to warrant not adding any annotations to the language?

Re: Revenge of the Types

#19
post #7

Random question for the type experts out there: is there any language that lets me track the units of my numeric variables? For instance, something like this: float drop(float x0, float duration) { float x = x0; float t = 0; float v = 0; float g = -10; float dt = 0.01; while (t /1000 ); // abbrev for a cast: (float ).001 } Then I want the compiler to check that I'm not mixing up my units. It seems like this would be…

Nimrod features distinct types (http://build.nimrod-lang.org/docs/manual.html#distinct-type) which allow you to implement something like this. Here is an example: https://github.com/def-/units/blob/master/units.nim#L220, I don't think it's complete yet though.

Re: Revenge of the Types

#20
post #7

Random question for the type experts out there: is there any language that lets me track the units of my numeric variables? For instance, something like this: float drop(float x0, float duration) { float x = x0; float t = 0; float v = 0; float g = -10; float dt = 0.01; while (t /1000 ); // abbrev for a cast: (float ).001 } Then I want the compiler to check that I'm not mixing up my units. It seems like this would be…

Scala has a number of libraries that lets you do this, for example Squants (http://www.squants.com/) and ScalaQuantity [https://github.com/zzorn/ScalaQuantity].
Post reply on HN