The following wonderful replies are from the C ++ discussion group: Why besides the type system? I haven't read every part of the discussion, but let me try to highlight some points of semantics here. I have not read all the sections in this discussion, but please highlight some points in this discussion. Let's assume we have a fully dynamic, stronugly-typed language, I. e. there is no type checking at translation time, but still every value has a type that can be queried. variables are not associated with fixed types, however, nor are functions. functions
Themselves are first-class citizens, and can be passed around and combined. (think lisp, JavaScript, or Haskell .) suppose we have a completely dynamic strong type language. That is to say, although there is no compilation period type check in the language, all values have a type that can be queried. Variables are not associated with fixed types, and so are functions. A function itself is a first-class citizen. It can be transmitted or combined. (Consider the lisp, JavaScript, or Haskell language ). Now this language has a facility that allows dynamic type checking. I can write a type assertion, I. e. "expr: int ". this will check, at runtime, that the value yielded by an expression is int. furthermore, types are fully reified and first-class citizens
Too, so I can write "t = int" and then do "expr: T ". (think Ruby or smalltalk, where classes are fully reified .) because types are values, I can write functions that take and return types. currently, this language provides a facility for dynamic type checks. I can write a type assertion, such as "expr: int ". At runtime, this assertion checks whether the value generated by an expression is int. In addition, the type is fully materialized and is a first-class citizen, so I can write "t = int" and then make (type assertions) "expr: T ". (Consider the languages in which Ruby or Smalltalk is fully materialized .) Because the type is also a value, I can write some functions that can receive and return the type. Let's look at C ++. Let's take a look at C ++. In C ++, we have various different kinds of things. In C ++, we have various types of things. On the first level, we have values. values have a type. (Let's leave value categories Out Of This .) this type is not itself a value, though; it is a different kind of thing. we cannot treat values as types or types as values. we also have functions, which
Are similar to values, but somewhat hobbled. we cannot pass functions und, only pointers to them. we can emulate everything you can do with functions with function objects (including Lambdas) though. we define functions that take and return values. at the first level, we have "value" and "value" types. (Do not consider the value category for the moment) the type itself is not a value, and the type and value are not one thing. We cannot regard a value as a type or a type as a value. We also have functions. functions are similar to values, but they are not free to use. The function cannot be passed in, and the function pointer can. However, we can use function objects (including lambda expressions) to simulate all functions of a function. We can define some functions that can receive and return "values. Values are runtime entities for the most part, but with non-type template arguments and constexpr, they have some role in compile time as well. values are runtime entities in most cases. However, if you use non-type template parameters and constexpr, values can also play a role during compilation. On the second level, we have types. types are almost purely compile time constructs, whose t for the extremely crippled type_info class, which is more of a type token than anything else. in C ++, we write type assertions, which get checked at compile time,
By associating functions and variables with types. On the second layer, We have types. The type is almost purely a compilation structure, except for the extremely incomplete type_info class. This class is more of a type identifier. In C ++, we can write type assertions. By associating functions, variables, and types, type assertions are checked during compilation. Then there's templates. Then there is the template. Templates are, mathematically speaking, functions that can only be called at compile time. A class template is a function that takes a bunch of parameters (types, values, and templates, I. e. other functions) and returns a type, which itself is composed
Of types (nested types), values (member constants and functions), and functions (nested templates ). A function template is a function that takes parameters and returns a function. it is really just a limited form of a class template-Aside from argument deduction,
Any function template can be emulated by a class template with a nested static function. The template, in mathematics, is a number of functions that can only be called during compilation. A class template is a function that receives a bunch of parameters (including types, values, templates, and other functions) and returns a type. The returned type is also composed of some types (nested type), values (member constants and member functions), and functions (nested templates. A function template is a function that receives a bunch of parameters and returns a function. Without considering the parameter derivation function, it is actually a restricted form of class templates. Any function template can be simulated using a class template with built-in static functions. The above is a bit of a mess. what I think frankhb wants is a simplification of the above. we cocould relax the restrictions on compile time values to allow everything, and then reify types so that they are values. then we can replace templates by constexpr
Functions that return types, and aside from the pesky issue of Type equivalence (name-based equivalency does not play well with fully reified types) It wowould all be fine. The above is a bit messy. I think frankhb wants to simplify the above features. We can relax the value restrictions during the compilation period so that everything can be a value, so that the type is materialized and becomes a value. Then we can replace the template with the constexpr function of the return type. In addition to the annoying type equivalence problem (name-based determining whether the equivalence is not a perfect combination of fully materialized types), everything will be perfect. Of course, the syntax of C ++ quite disagrees. the problem is that the kind distinction is necessary to disambiguiate the syntax. does "a B (c)" declare a function or a variable with an initializer? Is "A <B> (c)" A comparison (A, B and C are values), a function
Call (A is a function template), a variable declaration (A is a class template ), or a function-style cast (A is a class template and the code is part of a larger expression )? These are all very different things, and may influence how the compiler interprets
The rest of the Code. Of course, it is difficult to simplify the above with the c ++ syntax. The problem is that type screening is necessary to eliminate syntax ambiguity. Is "a B (c)" declared a function or a variable with an initiatator? "A <B> (c)" is a comparison operation (A, B, and C are both values), callback function call (A is a function template ), is a variable declaration (A is a class template) or a struct function type conversion (A is a class template and this part of code is part of a larger expression? These are all very different things. (the result of type determination) may affect how the compiler interprets the rest of the code. So while a language where types are first-class citizens that must be fully computable at compile time might be an interesting thing, C ++ is not that language, and will not be. I simply can't see any viable transition path. therefore, if a language type is a first-class citizen that can be fully calculated during the compilation period, it may be interesting. However, C ++ is not such a language and will never. I don't see any practical means of transformation at all. Did that clear anything up, or did I just add further to the confusion? Have I made my point clear, or just make it more ambiguous?
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.