let 与 -XRankNTypes 一起使用时不起作用

布拉德恩

考虑以下最小示例:

{-# LANGUAGE RankNTypes #-}

module Test where

class C w

data A = A (forall u. C u => u)

x :: forall u. C u => u
x = undefined

a = A x

正如预期的那样,这种类型检查很好。但是,如果a重构为使用let语句:

{-# LANGUAGE RankNTypes #-}

module Test where

class C w

data A = A (forall u. C u => u)

x :: forall u. C u => u
x = undefined

a = let x' = x in A x'

它突然无法键入检查并出现以下错误:

test.hs:12:14: error:
    * No instance for (C u0) arising from a use of `x'
    * In the expression: x
      In an equation for x': x' = x
      In the expression: let x' = x in A x'
   |
12 | a = let x' = x in A x'
   |              ^

test.hs:12:21: error:
    * Couldn't match expected type `u' with actual type `u0'
        because type variable `u' would escape its scope
      This (rigid, skolem) type variable is bound by
        a type expected by the context:
          forall u. C u => u
        at test.hs:12:19-22
    * In the first argument of `A', namely x'
      In the expression: A x'
      In the expression: let x' = x in A x'
    * Relevant bindings include x' :: u0 (bound at test.hs:12:9)
   |
12 | a = let x' = x in A x'

为什么会这样?这不违反等式推理吗?

n. '代词' m.

这是可怕的单态限制的结果。启用XNoMonomorphismRestriction应该导致它编译。

a = let x' = x in A x'不是等同于a = A x,因为下单态限制x'let x' = ...是单态,但A需要多态的参数。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

与ThrowsA一起使用时,TypeMatcher不起作用

为什么在Ubuntu上“ let”不能与“ sh myscript”一起使用,而对“ ./myscript”却起作用?

与 let 构造一起使用时,间距如何影响通配符?

将ES6 let与firefox和angular一起使用时,无法实例化模块

与apache Alias一起使用时,htaccess文件存在的检查似乎不起作用

将UpdateOne与MongoDB Golang驱动程序一起使用时Upsert不起作用

自定义授权器与AWS Chalice一起使用时不起作用

htmlentities()与表中的数据一起使用时不起作用

与 python3 一起使用时,ConfigParser 库不起作用

Python Pandas:与apply()一起使用时功能不起作用

与Google App Engine和Flask一起使用时,角线路线不起作用

Laravel 5-与重定向一起使用时withInput不起作用

与Ionic Framework一起使用时,Charset UTF 8不起作用

Ansible 设置模块的过滤器在与 playbook 一起使用时不起作用

与Onsen UI一起使用时,Videogular控制器不起作用

与plt.show一起使用时cv2.imshow不起作用

与popen python一起使用时,输入命令似乎不起作用

Bootstrap切换chechkbox与html helper chechkboxfor一起使用时不起作用?

:selected与rails形式的collection_select一起使用时不起作用

与Sass功能一起使用时,Sass分割不起作用

与“手表”一起使用时,“ awk”不起作用

与Radium和Material-UI一起使用时,React悬停样式不起作用

PHP if else 在将多变量与 OR 一起使用时不起作用

cat命令:与文件一起使用时,stdin重定向不起作用

修饰符与 .apply 一起使用时不起作用

与 Plus/Min 按钮一起使用时,innerHTML 不起作用

与客户拦截器一起使用时,Axios捕获不起作用

与导航抽屉一起使用时,工具栏的后退按钮不起作用

在Powershell中与正则表达式一起使用时,Leftpad不起作用