5 ms·
auto is type inference. That's not "pythonic", that's something that statically typed languages have had for decades. Indeed, it's nothing like Python, where ge
by massysett 11y ago
auto is type inference. That's not "pythonic", that's something that statically typed languages have had for decades. Indeed, it's nothing like Python, where general practice is to pass around things derived from Object and depend on runtime typing failures.
There's also nothing Pythonic about lambdas. Come on, lisp is ancient and it has lambdas.
This article essentially says C++ got stuff that has been around for decades, and Python has stuff that vaguely resembles them, so C++ is learning from Python.
- catnaroek 11y ago`auto` is just bottom-up type derivation, not really type inference. Type inference lets you recover the type of a variable from how the variable is used, not just from how it is initialized. Implementation-wise, bottom-up type derivation only requires unidirectional type propagation, whereas type inference requires solving arbitrary systems of type equations. The former is a special case of the latter, where all equations are of the form “X = T”, where “X” is a type variable and “T” is an arbitrary type expression. No type inference: http://ideone.com/fmm92M http://ideone.com/fmm92M, http://ideone.com/HzyM2E http://ideone.com/HzyM2E Type inference: http://ideone.com/0Gv8fV http://ideone.com/0Gv8fV, http://ideone.com/r9nHUF http://ideone.com/r9nHUF
- dllthomas 11y agoIt's clearly not type inference in its full generality (or all that close, really), but it seems a bit odd to say "X is a special case of Y; A is doing X; A is doing no Y".
- catnaroek 11y agoType inference is performed by scanning the program, generating a system of type equations and solving it. If all type equations are of the form “X = T”, then there's nothing to solve.
- fauigerzigerk 11y agoType inference is inferring a type where none has been specified explicitly. There are certainly more or less advanced forms of it, but solving systems of type equations is not the definition of type inference.
- catnaroek 11y agoOn what type inference is, from a PL researcher: http://lambda-the-ultimate.org/node/4771#comment-75771 http://lambda-the-ultimate.org/node/4771#comment-75771
- fauigerzigerk 11y agoThere will always be some who insist that only the most advanced form of X is "really" X.
- catnaroek 11y agoML-style type inference is hardly “advanced”. And I'm even willing to count more limited forms of inference as seen in Scala, Rust or Swift - what they have is only local, but it's actual inference. But what you're claiming is the equivalent of having a “number inference” engine that can conclude that “x = 8” from “x = 4 * 2” - that's not “inference”, it's just evaluating a single expression. Actually, what Go has is even less than that, because Go's type checker doesn't need to reduce anything.
- fmap 11y agoIt's more of a vocabulary issue. In PL theory "type inference" is a well-defined concept. It means that you have the ability to reconstruct the types of a program without annotations. No mainstream (imperative) programming language has type inference in this sense (for good reasons). That's why the term is usually used with a different meaning when talking about mainstream programming languages.
- sklogic 11y agoIn case of a C++ auto, type is specified explicitly - it is an RHS type of an assignment. Type is not deduced here, it is symply propagated. Auto does not add anything new at all on top of the existing type checking: if for a specific LHS type a checker would normalise both left and right hand types and check for assignability, in case of auto it will assume LHS=RHS without checking anything. Therefore auto is a subset of type propagation, not type inference.
- cwyers 11y agoThe lambdas one is the one that got me - the best word I can use for Python's lambda support is "grudgingly."
- deleted 11y ago[deleted]
- deleted 11y ago[deleted]