3 ms·
Honest question: Is Python-with-type-hinting-in-function-definitions (and maybe type assertions) equally as "strong" as common style Python? It's not static t
by thanatropism 9y ago
Honest question:
Is Python-with-type-hinting-in-function-definitions (and maybe type assertions) equally as "strong" as common style Python?
It's not static typing -- it's not Haskell -- but it's already a step further.
Edit: I find myself doing a lot of "assert isinstance(x,foo)".
- dragonwriter 9y agoHaskell types don't exist at runtime. If you use a static analyzer like mypy, Python types are “static” in the same sense as Haskell (statically verified as correct in advance), though mypy’s type system is less robust than Haskell’s.
- thanatropism 9y agoI'm not knowledgeable of this stuff, but I'll keep taxing your patience until you tell me to stop. Haskell types don't exist at runtime... because Haskell code (like with any other compiled language) gets translated to a lower-level machine language that works with untyped memory addresses? Or are you saying that (for example) Fortran types are closer to the metal somehow?
- shakna 9y agoHaskell types don't exist at runtime, because you can't check a type at runtime. Any type-checking has to happen at compile time, because that information doesn't make it through. So, something like Python's isinstance or type functions can't exist.
- rifung 9y agoSorry if dumb question. If Haskell types don't exist at runtime how do type class functions work? I'd think the type needs to get inspected to choose the implementation to call?
- msla 9y agoIt seems like it's about as strong, in terms of what types it knows about, but it allows more error detection at "compile time" or, at least, the time at which you run the static type-checking code on the codebase. As Guido said, this is like a super-linter. https://www.python.org/dev/peps/pep-0484/ https://www.python.org/dev/peps/pep-0484/ (I remember C linters trying to expand the C type system by doing things like complaining if you used non-boolean expressions in a boolean context, well before C had an actual bool type.)