3 ms·
Are assignment expressions the only linguistic change? For years,I've been holding my breath in Python for sum types, totality checking, and an enforced, compl
by Jeff_Brown 8y ago
Are assignment expressions the only linguistic change?
For years,I've been holding my breath in Python for sum types, totality checking, and an enforced, complete type system -- one where you can say "this should be a list of lists of integers" and it won't let you put any other kind of thing there.
(Yes, there are external typing solutions like PyPy, but last I checked they did not offer complete type systems (you could specify that something is a list, but not that it's a list of ints), nor did they permit totality checking (so if type X is a sum type with two constructors X1 and X2, and f is a function that takes an X as input, and you forgot to define what happens if f is given an X2, it would not know to complain that you hadn't covered all possibilities).
- netheril96 8y ago> but not that it’s a list of ints Python type annotations do support such use case: List[int].
- Jeff_Brown 8y agoOmg really? Sweet! What about functions, and functions of functions, etc? Can I specify that the argument to function f should be some other function g which should receive a list of ints and return a dict of functions with keys that are ints and values that are functions from int to int?
- detaro 8y agoYes, you can do that too.
- Jeff_Brown 8y agoJust tried it. What's the point of type signatures if the compiler won't hold you to the promises you've made? This is in Python 3.6.4: >>> def f (x:int) -> int: return x+1 ... >>> def g (x:str) -> str: return f(x) ... >>> g(1) 2 I expected a complaint after the second definition: I specified that g takes and returns a string, and then defined it to take and return an int. Not only did Python not catch the error at compile time (defining g), it didn't even catch it at runtime (calling g).
- netheril96 8y agoFor some strange reasons Python developers decide to provide the syntax of type annotations but leave the actual checking to third party implementations.
- detaro 8y agoType annotations are just that: annotations. They currently have no meaning to the CPython interpreter and are purely consumed by external tooling (IDEs, there's a static typechecker called mypy, ...) or code that chooses to use them (e.g. there's web frameworks that convert and validate parameter types according to the signature of the handler function)
- mixmastamyk 8y ago> an enforced, complete type system You are looking at the wrong language. That said, the array module has been around for ages, for performance reasons.
- Jeff_Brown 8y agoI use Haskell outside of work, and absolutely love it. (And in its case, too, I'm holding my breath for dependent types, which I believe are expected around summer of 2020.)