溶血症是什么症状| 河粉为什么叫河粉| 舌尖有裂纹是什么原因| 胃疼看病挂什么科| 无拘无束的意思是什么| 心什么神什么| 榴莲为什么这么贵| 王维是诗什么| 方解石玉是什么玉| 青梅煮酒什么意思| hpv通过什么传播| 什么中药减肥| 肚子有硬块是什么原因| 低血压高吃什么药| 巨蟹男和什么星座最配| 什么是腺样体肥大| 什么鱼炖豆腐好吃| 什么光会给人带来痛苦| 双脚浮肿是什么原因| 气血不通吃什么药| 三头六臂指什么生肖| 56年属什么| 咽喉充血是什么原因| 为什么呢| 尘肺病吃什么能排出尘| 奇亚籽有什么功效| 来月经有异味什么原因| 武松的绰号是什么| 氯读什么拼音| 拔牙为什么要验血| 陈宝莲为什么自杀| 增生是什么原因造成的| 夏天流鼻血是什么原因| 极乐是什么意思| 王毅是什么级别| 格色是什么意思| zfc是什么牌子| 低血压吃什么补得最快| papi是什么意思| 党参和丹参有什么区别| 11月24日是什么星座| 什么的歌声| 狼毫毛笔是什么毛| 金什么| 棚改是什么意思| 媒婆是什么意思| 老人嘴唇发紫是什么原因| 财大气粗是什么意思| 什么病需要做透析| 装孙子是什么意思| 尿液特别黄是什么原因引起的| 什么山| 意阑珊什么意思| 10月7日是什么星座| 婴儿坐高铁需要什么证件| 夜场是什么工作| 投喂是什么意思| 哥哥的老婆叫什么| 眼睛红痒用什么眼药水| 老梗是什么意思| 异质性是什么意思| 葛根粉有什么作用| 晚上睡觉手发麻是什么原因| 镶牙和种牙有什么区别| 不吃肉对身体有什么影响| 上火引起的喉咙痛吃什么药| 字母圈是什么意思| 乙肝五项145阳性是什么意思| 补阳气吃什么| 梦见狼是什么意思| 泡温泉穿什么衣服| bebe是什么意思| 产后为什么脸部松弛| 轻度三尖瓣反流是什么| 阴囊瘙痒用什么药最好| 癫痫属于什么科| 假性宫缩是什么感觉| 肩膀疼挂什么科室最好| 奶茶和奶绿有什么区别| 入职体检70元一般检查什么| 古代人用什么刷牙| 谷氨酰转肽酶是指什么| 白马怕青牛是什么意思| 中国国菜是什么菜| 脚心痒是什么原因引起的| 6个月宝宝可以吃什么水果| 腰间盘突出有什么症状| 舌头发麻看什么科| 6朵玫瑰代表什么意思| 什么的天| 蜘蛛怕什么| 白带多是为什么| 非典型鳞状细胞意义不明确是什么意思| 6月27是什么星座| 霍乱时期的爱情讲的是什么| 头孢是治疗什么的| 什么是g点| ad是什么病| 缺磷吃什么食物好| 水痘是什么样的| 2027年属什么生肖| 高原反应的原因是什么| 什么是营养| 不想要孩子用什么办法最好| 酸汤鱼用什么鱼| 劝君更尽一杯酒的下一句是什么| 胃造影和胃镜有什么区别| 早上起床牙龈出血是什么原因| 纸是什么生肖| 卡路里什么意思| 门特是什么| 十月初七是什么星座| 属猪生什么属相宝宝好| 宫颈多发纳氏囊肿是什么意思| beacon什么意思| 秀恩爱是什么意思| 忘带洗面奶用什么代替| 孕妇梦到蛇是什么意思| 什么的足迹| nothomme什么牌子| 打感情牌是什么意思| 四月初八是什么日子| 产后复查都查什么| 左肺结节是什么意思| 肺栓塞是什么意思| cps是什么意思啊| 抱大腿什么意思| 什么样的天山| 直肠给药对小孩身体有什么影响| 广州有什么玩的| 芙蓉花长什么样| 什么体质容易长肿瘤| 肺部感染有什么症状| 5月24号是什么日子| 11月18号是什么星座的| 梦见仙鹤是什么意思| 精神慰藉什么意思| 富三代是什么意思| 柳絮吃了有什么好处| 混合痔是什么意思| 傻白甜的意思是什么| 芦荟有什么作用| 胸腔疼挂什么科| 软化灶是什么意思| 牙齿出血是什么病征兆| 身体水肿是什么原因引起的| 过江龙是什么意思| 盐水是什么| 怼怼是什么意思| 抹布是什么意思| 虚是什么意思| 屋里有蝙蝠有什么预兆| 扁桃体发炎吃什么中成药| 急性肠胃炎吃什么药好| 付之一炬什么意思| 84消毒液不能和什么一起用| 挑食是什么意思| pc是什么意思| 属猴和什么属相相冲| led什么意思| 什么人招蚊子| 两岁宝宝拉肚子吃什么药| 降血糖吃什么药| 做梦梦到很多蛇是什么意思| 当归长什么样的图片| cc代表什么意思| 空调漏水是什么原因| 扬长而去是什么意思| 不容乐观是什么意思| 汪星人什么意思| 多动症是什么原因造成| 欲盖弥彰什么意思| 什么情况要做支气管镜| 夏天适合种植什么蔬菜| 挂号是什么意思| bpm什么意思| 浓茶喝多了有什么危害| 后脑两侧痛是什么原因| 回盲瓣呈唇形什么意思| 棕色皮鞋配什么颜色裤子| 24k黄金是什么意思| 冰雹是什么季节下的| 舌头疼吃什么药| 利可君片是什么药| 中老年人补钙吃什么牌子的钙片好| 鹅蛋不能和什么一起吃| 肾积液是什么原因造成的| msi是什么比赛| 穹隆什么意思| 英特纳雄耐尔是什么意思| 每天做梦是什么原因引起| 孕妇胆固醇高对胎儿有什么影响| 什么动物没有耳朵| 梦见买手表是什么预兆| 吃什么败火| 喉炎是什么原因引起的| 力挺是什么意思| 彩色相片什么时候出现| 湿温病是什么症状| 异位妊娠是什么意思| 交接是什么意思| 肌病是什么病| 草莓是什么形状| 什么叫尊重| 甲状腺功能是什么| 锦是什么意思| 正月二十是什么星座| 鼻窦炎用什么药好| 子宫内膜异位症有什么症状表现| 建字五行属什么| 细佬什么意思| 为什么不开朱元璋的墓| 挂号特需是什么意思| 1965属什么生肖| 受用是什么意思| 什么人一年只工作一天脑筋急转弯| 女的什么时候退休| 减肥期间能吃什么水果| 喝酒脸红是什么原因| 送表的寓意是什么| 甲钴胺片有什么副作用| 饭后散步有什么好处| 日本牛郎是干什么的| 腰酸痛是什么原因| 姜黄与生姜有什么区别| 惘然什么意思| 我方了是什么意思| 睡醒后口干口苦是什么原因| 打嗝是什么病| 大便量少是什么原因| h是什么元素| 尿比重高是什么原因| 开普拉多的都是什么人| mect是什么意思| 跳闸是什么原因| 十万为什么| 我炸了是什么意思| 乔治白属于什么档次| landrover是什么车| 禅宗是什么意思| 胚胎停育是什么原因造成的| 通情达理是什么意思| 血红蛋白升高说明什么| 备孕不能吃什么| 安欣是什么电视剧| 复方丹参片治什么病| 耳朵疼吃什么消炎药| 发高烧是什么原因引起的| 职业年金是什么意思| 打碎碗是什么预兆| 血热是什么意思| 潜伏是什么意思| 多发性结节是什么意思| 朋友是什么| 阳虚和阴虚有什么区别| 倪妮和倪萍什么关系| 兔子的眼睛为什么是红色的| 脖子肿了是什么原因| 血压偏低是什么原因| 老虎拉车的歇后语是什么| 阴谋是什么意思| 发质硬适合什么发型| 水为什么是蓝色的| 红霉素软膏和红霉素眼膏有什么区别| 百度

希特勒《我的奋斗》进日教材 网友:政府在发疯

百度 从履历看,严植婵、胡文容均系2017年首次当选省委常委,本次调整为两人首次异地任职。

In programming languages and type theory, parametric polymorphism allows a single piece of code to be given a "generic" type, using variables in place of actual types, and then instantiated with particular types as needed.[1]:?340? Parametrically polymorphic functions and data types are sometimes called generic functions and generic datatypes, respectively, and they form the basis of generic programming.

Parametric polymorphism may be contrasted with ad hoc polymorphism. Parametrically polymorphic definitions are uniform: they behave identically regardless of the type they are instantiated at.[1]:?340?[2]:?37? In contrast, ad hoc polymorphic definitions are given a distinct definition for each type. Thus, ad hoc polymorphism can generally only support a limited number of such distinct types, since a separate implementation has to be provided for each type.

Basic definition

edit

It is possible to write functions that do not depend on the types of their arguments. For example, the identity function   simply returns its argument unmodified. This naturally gives rise to a family of potential types, such as  ,  ,  , and so on. Parametric polymorphism allows   to be given a single, most general type by introducing a universally quantified type variable:

 

The polymorphic definition can then be instantiated by substituting any concrete type for  , yielding the full family of potential types.[3]

The identity function is a particularly extreme example, but many other functions also benefit from parametric polymorphism. For example, an   function that concatenates two lists does not inspect the elements of the list, only the list structure itself. Therefore,   can be given a similar family of types, such as  ,  , and so on, where   denotes a list of elements of type  . The most general type is therefore

 

which can be instantiated to any type in the family.

Parametrically polymorphic functions like   and   are said to be parameterized over an arbitrary type  .[4] Both   and   are parameterized over a single type, but functions may be parameterized over arbitrarily many types. For example, the   and   functions that return the first and second elements of a pair, respectively, can be given the following types:

 

In the expression  ,   is instantiated to   and   is instantiated to   in the call to  , so the type of the overall expression is  .

The syntax used to introduce parametric polymorphism varies significantly between programming languages. For example, in some programming languages, such as Haskell, the   quantifier is implicit and may be omitted.[5] Other languages require types to be instantiated explicitly at some or all of a parametrically polymorphic function's call sites.

History

edit

Parametric polymorphism was first introduced to programming languages in ML in 1975.[6] Today it exists in Standard ML, OCaml, F#, Ada, Haskell, Mercury, Visual Prolog, Scala, Julia, Python, TypeScript, C++ and others. Java, C#, Visual Basic .NET and Delphi have each introduced "generics" for parametric polymorphism. Some implementations of type polymorphism are superficially similar to parametric polymorphism while also introducing ad hoc aspects. One example is C++ template specialization.

Predicativity, impredicativity, and higher-rank polymorphism

edit

Rank-1 (predicative) polymorphism

edit

In a predicative type system (also known as a prenex polymorphic system), type variables may not be instantiated with polymorphic types.[1]:?359–360? Predicative type theories include Martin-L?f type theory and Nuprl. This is very similar to what is called "ML-style" or "Let-polymorphism" (technically ML's Let-polymorphism has a few other syntactic restrictions). This restriction makes the distinction between polymorphic and non-polymorphic types very important; thus in predicative systems polymorphic types are sometimes referred to as type schemas to distinguish them from ordinary (monomorphic) types, which are sometimes called monotypes.

A consequence of predicativity is that all types can be written in a form that places all quantifiers at the outermost (prenex) position. For example, consider the   function described above, which has the following type:

 

In order to apply this function to a pair of lists, a concrete type   must be substituted for the variable   such that the resulting function type is consistent with the types of the arguments. In an impredicative system,   may be any type whatsoever, including a type that is itself polymorphic; thus   can be applied to pairs of lists with elements of any type—even to lists of polymorphic functions such as   itself. Polymorphism in the language ML is predicative.[7] This is because predicativity, together with other restrictions, makes the type system simple enough that full type inference is always possible.

As a practical example, OCaml (a descendant or dialect of ML) performs type inference and supports impredicative polymorphism, but in some cases when impredicative polymorphism is used, the system's type inference is incomplete unless some explicit type annotations are provided by the programmer.

Higher-rank polymorphism

edit

Some type systems support an impredicative function type constructor even though other type constructors remain predicative. For example, the type   is permitted in a system that supports higher-rank polymorphism, even though   may not be.[8]

A type is said to be of rank k (for some fixed integer k) if no path from its root to a   quantifier passes to the left of k or more arrows, when the type is drawn as a tree.[1]:?359? A type system is said to support rank-k polymorphism if it admits types with rank less than or equal to k. For example, a type system that supports rank-2 polymorphism would allow   but not  . A type system that admits types of arbitrary rank is said to be "rank-n polymorphic".

Type inference for rank-2 polymorphism is decidable, but for rank-3 and above, it is not.[9][1]:?359?

Impredicative polymorphism

edit

Impredicative polymorphism (also called first-class polymorphism) is the most powerful form of parametric polymorphism.[1]:?340? In formal logic, a definition is said to be impredicative if it is self-referential; in type theory, it refers to the ability for a type to be in the domain of a quantifier it contains. This allows the instantiation of any type variable with any type, including polymorphic types. An example of a system supporting full impredicativity is System F, which allows instantiating   at any type, including itself.

In type theory, the most frequently studied impredicative typed λ-calculi are based on those of the lambda cube, especially System F.

Bounded parametric polymorphism

edit

In 1985, Luca Cardelli and Peter Wegner recognized the advantages of allowing bounds on the type parameters.[10] Many operations require some knowledge of the data types, but can otherwise work parametrically. For example, to check whether an item is included in a list, we need to compare the items for equality. In Standard ML, type parameters of the form ’’a are restricted so that the equality operation is available, thus the function would have the type ’’a × ’’a list → bool and ’’a can only be a type with defined equality. In Haskell, bounding is achieved by requiring types to belong to a type class; thus the same function has the type   in Haskell. In most object-oriented programming languages that support parametric polymorphism, parameters can be constrained to be subtypes of a given type (see the articles Subtype polymorphism and Generic programming).

See also

edit

Notes

edit
  1. ^ a b c d e f Benjamin C. Pierce (2002). Types and Programming Languages. MIT Press. ISBN 978-0-262-16209-8.
  2. ^ Strachey, Christopher (1967), Fundamental Concepts in Programming Languages (Lecture notes), Copenhagen: International Summer School in Computer Programming. Republished in: Strachey, Christopher (1 April 2000). "Fundamental Concepts in Programming Languages". Higher-Order and Symbolic Computation. 13 (1): 11–49. doi:10.1023/A:1010000313106. ISSN 1573-0557. S2CID 14124601.
  3. ^ Yorgey, Brent. "More polymorphism and type classes". www.seas.upenn.edu. Retrieved 1 October 2022.
  4. ^ Wu, Brandon. "Parametric Polymorphism - SML Help". smlhelp.github.io. Archived from the original on 1 October 2022. Retrieved 1 October 2022.
  5. ^ "Haskell 2010 Language Report § 4.1.2 Syntax of Types". www.haskell.org. Retrieved 1 October 2022. With one exception (that of the distinguished type variable in a class declaration (Section 4.3.1)), the type variables in a Haskell type expression are all assumed to be universally quantified; there is no explicit syntax for universal quantification.
  6. ^ Milner, R., Morris, L., Newey, M. "A Logic for Computable Functions with reflexive and polymorphic types", Proc. Conference on Proving and Improving Programs, Arc-et-Senans (1975)
  7. ^ Mitchell, J. C.; Harper, R. (2025-08-07). "The essence of ML". Proceedings of the 15th ACM SIGPLAN-SIGACT symposium on Principles of programming languages - POPL '88. New York, NY, USA: Association for Computing Machinery. pp. 28–46. doi:10.1145/73560.73563. ISBN 978-0-89791-252-5.
  8. ^ Kwang Yul Seo. "Kwang's Haskell Blog - Higher rank polymorphism". kseo.github.io. Retrieved 30 September 2022.
  9. ^ Kfoury, A. J.; Wells, J. B. (1 January 1999). "Principality and decidable type inference for finite-rank intersection types". Proceedings of the 26th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. Association for Computing Machinery. pp. 161–174. doi:10.1145/292540.292556. ISBN 1581130953. S2CID 14183560.
  10. ^ Cardelli & Wegner 1985.

References

edit
ctm是什么意思 braun是什么品牌 耳石症眩晕吃什么药 绝什么意思 肺阴虚吃什么中成药
免疫力和抵抗力有什么区别 如意丹的作用是什么 甲钴胺片主要治什么病 耳朵响是什么原因引起的 黑色粑粑是什么原因
什么情况吃通宣理肺丸 血管瘤吃什么药 沈阳有什么大学 便秘应该挂什么科室 戊是什么生肖
肚脐眼周围痛挂什么科 探囊取物是什么意思 水瓶座的性格是什么 输卵管发炎有什么症状表现 菠菜补什么
脑淤血是什么原因引起的hcv8jop8ns5r.cn 03年是什么年hcv8jop3ns4r.cn amor是什么意思hcv7jop7ns0r.cn 银杏叶提取物治什么病hcv8jop6ns1r.cn 物心念什么sscsqa.com
6.8是什么星座hcv8jop6ns7r.cn 支气管炎是什么原因引起的hcv8jop9ns7r.cn 985是什么意思hcv8jop3ns2r.cn 红豆为什么代表相思hcv9jop1ns6r.cn 卡介苗为什么会留疤hcv7jop5ns5r.cn
面色少华是什么意思xjhesheng.com 降压药的原理是什么hanqikai.com 吃什么东西补血hcv9jop3ns0r.cn 什么是abo文hcv7jop9ns1r.cn 晟念什么字hcv9jop1ns3r.cn
检查食管做什么检查hcv8jop4ns5r.cn noa是什么意思hcv7jop9ns6r.cn 蚂蚁最怕什么hcv8jop7ns1r.cn 什么什么害命hcv7jop9ns3r.cn 胃暖气是什么症状hcv9jop6ns5r.cn
百度