- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
多态性的等级和(非)预测性之间有什么关系?
1 级多态性可以是谓词还是非谓词?
可以用 k > 1
对 k 多态性进行排序是谓语还是非谓语?
我的困惑来自:
为什么https://en.wikipedia.org/wiki/Parametric_polymorphism提到等级 1 多态性下的预测性? (在我看来,rank-1 意味着可预测性)
Rank-1 (prenex) polymorphism
In a prenex polymorphic system, type variables may not be instantiated with polymorphic types.[4] 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 is that all types can be written in a form that places all quantifiers at the outermost (prenex) position. For example, consider the append function described above, which has type
forall a. [a] × [a] -> [a]
In order to apply this function to a pair of lists, a type must be substituted for the variable
a
in the type of the function such that the type of the arguments matches up with the resulting function type.In an impredicative system, the type being substituted may be any type whatsoever, including a type that is itself polymorphic; thus append can be applied to pairs of lists with elements of any type—even to lists of polymorphic functions such as append itself. Polymorphism in the language ML is predicative.[citation needed] 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.
...
Predicative polymorphism
In a predicative parametric polymorphic system, a type
τ
containing a type variableα
may not be used in such a way thatα
is instantiated to a polymorphic type. Predicative type theories include Martin-Löf Type Theory and NuPRL.
Impredicative types are an advanced form of polymorphism, to be contrasted with rank-N types.
Standard Haskell allows polymorphic types via the use of type variables, which are understood to be universally quantified:
id :: a -> a
means "for all typesa
,id
can take an argument and return a result of that type". All universal quantifiers ("for all"s) must appear at the beginning of a type.Higher-rank polymorphism (e.g. rank-N types) allows universal quantifiers to appear inside function types as well. It turns out that appearing to the right of function arrows is not interesting:
Int -> forall a. a -> [a]
is actually the same asforall a. Int -> a -> [a]
.However, higher-rank polymorphism allows quantifiers to the left of function arrows, too, and
(forall a. [a] -> Int) -> Int
really is different fromforall a. ([a] -> Int) -> Int
.Impredicative types take this idea to its natural conclusion: universal quantifiers are allowed anywhere in a type, even inside normal datatypes like lists or
Maybe
.
最佳答案
Can rank-1 polymorphism be either predicative or impredicative?
forall
量词不会作为类型构造函数的参数出现,也就是说,量词是“prenex”。
Can rank-k polymorphism with k > 1 be either predicative or impredicative?
RankNTypes
扩展只为
(->)
启用不可预测的多态性构造函数,即给定类型
a -> b
,
a
或
b
可以使用包含
forall
的类型实例化s。我们通常仅在
a
时才将此类类型称为更高等级包含
forall
s,因为(除了
TypeApplications
)
X -> forall t. Y
相当于
forall t. X -> Y
.
ImpredicativeTypes
扩展名)。例如,您不能写
Maybe (forall a. [a] -> [a])
.这主要是因为很难自动确定何时泛化以及何时实例化该量词。幸运的是,您可以使用
newtype
明确说明这一点。包装器来“隐藏”不可预测性,或者更确切地说,让编译器清楚你想对量词做什么,例如:
{-# LANGUAGE RankNTypes #-}
newtype ListTransform = ListTransform { unLT :: forall a. [a] -> [a] }
f :: Maybe ListTransform -> [Int] -> [Char] -> ([Int], [Char])
f Nothing is cs = (is, cs)
f (Just (ListTransform t)) is cs = (t is, t cs)
-- or: f (Just lt) is cs = (unLT lt is, unLT lt cs)
关于haskell - 多态性的等级和(非)预测性之间有什么关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58211077/
这可能是一个简单的“不可能”的答案,但我想确定一下。我目前正在使用 LibreOffice,但如果可以在 Excel 中使用,我可以切换。 我有一个包含几个表格的电子表格,每个表格都有不同数据的相同测
我有一个应用程序,并且在主gradle文件中编写: task myTask { def command = "wsimport -s src" + File.separator + "main
我正在尝试使用点云库从点云中分割一个平面,并且我有一些有关平面模型的先验信息(即法线应该类似于z轴,高度(d)应该大约为0) 。 有没有办法强制我的RANSAC算法选择与我先前模型相似的系数?我认为可
我正在为一个发票项目开发一个基于 excel 的设备数据库。每个独特的项目都有自己的工作簿,但我正在尝试构建一个模板工作簿来限制每个项目的发票中有多少手动工作。每件设备都有一个型号、序列号和允许的地址
嗨, friend 们,我正在开发位置查找应用程序,每次我进入 map 页面时,我都会收到如下警告: "Received memory warning. Level=1" 应用程序崩溃后,我不知道该怎
我在状态中设置了 score、topicTotal 和 level,我正在打印它们中的每一个。 topicTotal 是所有分数相加的最终分数,level 基于它们的 topicTotal。 scor
这个问题在这里已经有了答案: How can I change an element's class with JavaScript? (33 个答案) 关闭 4 年前。
是否可以根据条件扩展 Ember 类?像这样的事情: A.reopen({ if (condition) { init: function() { this.super();
我有以下 DataFrame,其中包含两组动物以及它们每天吃多少食物, df = pd.DataFrame({'animals': ['cat', 'cat', 'dog', 'dog', 'rat'
下面的代码尝试使用 mpi 查找数组的最大数量.但是我不断收到以下错误: Rank 2 in job 47 caused collective abort of all ranks. Exit sta
我在 Tensorflow 文档主页上找到以下关于在等级>2 时使用 matmul 操作的内容: https://www.tensorflow.org/api_docs/python/math_ops
我试图弄清楚如何将Android Library项目分发给某些Beta用户,但是在分发并将其用于示例项目时遇到了一些问题。我正在尝试分发AAR文件。 我的示例项目中的所有内容都可以正常编译,但出现错误
我收到了以下 gradle 构建文件 (gae.gradle),其中包含来自 SpringSource 的示例项目,但是当我尝试使用 gradle 运行它时: gradle gae 它生成错误: FA
我想知道基于我的数据库结构的排名: 我有一个模型 Post 属于一个名为 Edition 的模型(也是 one Edition 有很多 Post). 一个Post有很多Like。 我想根据特定 Edi
我试图在登录页面中向正文添加一个类“bodyLogin”,并在所有其他页面中将其删除。angular的方式应该怎么做? 最佳答案 正如 Jeremy 所建议的那样,我使用了 ng 类,但在自动设置 $
我从 PHPClasses 网站获得了以下 ELO 类。 $S2) { $E = 120 - round(1 / (1 + pow(10, (($R2 - $R1)
我是 Matlab/Octave 用户。 Numpy 文档说 array 比 matrix 更可取。有没有一种方便的方法来处理 rank-1 数组,而不需要不断地 reshape 它? 例子: dat
比如说,我使用 MPI 运行一个并行程序。执行命令 mpirun -n 8 -npernode 2 总共启动8个进程。即每个节点有 2 个进程,总共有 4 个节点。 (OpenMPI 1.5)。其中
我需要按分区(或组)对行进行排名,即如果我的源表是: NAME PRICE ---- ----- AAA 1.59 AAA 2.00 AAA 0.75 BBB 3.48 BBB 2.19 B
我必须从文件中填充 CMake 变量缓存。 我在defaultConfig.externalNativeBuild.cmake.arguments(-C options.cmake)中添加了一个参数。
我是一名优秀的程序员,十分优秀!