- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
根据定义,下面给出的代码片段是否符合合法标准 ML?它使用 Poly/ML 进行类型检查,但不使用 Moscow ML:
infixr 5 ::: ++
signature HEAP_ENTRY =
sig
type key
type 'a entry = key * 'a
val reorder : ('a -> key) -> 'a * 'a -> 'a * 'a
end
signature HEAP_TAIL =
sig
structure Entry : HEAP_ENTRY
type 'a tail
val empty : 'a tail
val cons : 'a Entry.entry * 'a tail -> 'a tail
val uncons : 'a tail -> ('a Entry.entry * 'a tail) option
val ++ : 'a tail * 'a tail -> 'a tail
end
signature SIMPLE_FOREST =
sig
structure Entry : HEAP_ENTRY
type 'a tree
type 'a tail = (int * 'a tree) list
val head : 'a tree -> 'a Entry.entry
val tail : int * 'a tree -> 'a tail
val cons : 'a Entry.entry * 'a tail -> 'a tail
val link : (int * 'a tree) * 'a tail -> 'a tail
end
structure IntRank =
struct
fun reorder f (x, y) = if f x <= f y then (x, y) else (y, x)
fun relabel' (_, nil, ys) = ys
| relabel' (r, x :: xs, ys) =
let val r = r - 1 in relabel' (r, xs, (r, x) :: ys) end
fun relabel (r, xs) = relabel' (r, xs, nil)
end
functor SimpleForestTail (F : SIMPLE_FOREST) :> HEAP_TAIL
where type Entry.key = F.Entry.key =
struct
open F
val empty = nil
fun link ((x, xs), ys) = F.link (x, xs ++ op:: ys)
and xs ++ nil = xs
| nil ++ ys = ys
| (op:: xs) ++ (op:: ys) = link (IntRank.reorder (#1 o #1) (xs, ys))
fun pick args = #1 (Entry.reorder (#1 o head o #2 o #1) args)
fun attach (x, (y, xs)) = (y, x :: xs)
fun extract (xs as (x, op:: ys)) = pick (xs, attach (x, extract ys))
| extract xs = xs
fun rebuild (x, xs) = (head (#2 x), tail x ++ xs)
fun uncons xs = Option.map (rebuild o extract) (List.getItem xs)
end
Moscow ML 给出的错误是:
File "test.sml", line 47-66, characters 45-631:
! .............................................:> HEAP_TAIL
! where type Entry.key = F.Entry.key =
! struct
! open F
! ..........
!
! fun rebuild (x, xs) = (head (#2 x), tail x ++ xs)
! fun uncons xs = Option.map (rebuild o extract) (List.getItem xs)
! end
! Signature mismatch: the module does not match the signature ...
! Scheme mismatch: value identifier uncons
! is specified with type scheme
! val 'a' uncons :
(int * 'a' tree) list -> ((key * 'a') * (int * 'a' tree) list) option
! in the signature
! but its declaration has the unrelated type scheme
! val uncons :
(int * 'a tree) list -> ((key * 'a) * (int * 'a tree) list) option
! in the module
! The declared type scheme should be at least as general as the specified type scheme
我尝试为 uncons
使用显式类型签名:
fun 'a uncons (xs : 'a tail) = Option.map (rebuild o extract) (List.getItem xs)
但这只会使错误消息更加本地化:
File "test.sml", line 65, characters 78-80:
! fun 'a uncons (xs : 'a tail) = Option.map (rebuild o extract) (List.getItem xs)
! ^^
! Type clash: expression of type
! (int * 'a tree) list
! cannot have type
! (int * 'b tree) list
! because of a scope violation:
! the type variable 'a is a parameter
! that is declared within the scope of 'b
如果有人感兴趣,这里是where the snippet originally came from .
最佳答案
问题出在第57行中#1
的使用。它涉及到一个本地未解析的记录类型。 SML 定义说“程序上下文必须唯一地确定”如何解析这样的类型并且可能需要类型注释。不幸的是,该定义并未说明相关程序上下文可能有多大。没有实现接受任意大上下文,并且没有发布可以处理该问题的完整有效算法,除非引入记录多态性(因此过于笼统)。因此,不更具体被认为是定义中的(已知)错误。
适用于所有实现的一个好的经验法则是最小的周围声明,即在本例中为 ++
的定义。 #1
的类型不能仅根据该定义来确定,因此许多实现将拒绝它,即使有些更宽松。
关于language-lawyer - 根据定义,这个片段是否合法标准 ML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38030223/
我一直在阅读Code Complete 2 .由于我不是以英语为母语的人,因此我需要一些时间才能理解某些陈述。我希望你描述作者在他的书中所做的这两个陈述之间的区别: You should progra
我将 TYPO3 安装从 8.6 升级到 9.5。在内容语言设置为“所有语言”的页面上,这些元素不会显示在前端。 似乎在 ContentObjectRenderer->getQueryConstrai
我和一个学生正在建立一个新的口译员家庭,我们希望以现有口译员为基准。我们很乐意下载包含 Computer Language Benchmarks Game 中使用的所有源代码的 tarball 或 z
因此,我正在尝试创建一个双语网站,只需单击一下即可将其从英语切换为葡萄牙语,反之亦然。 我收到此错误:Use of undefined constant language - assumed 'lan
我正在阅读一个比较不同编程语言的演示文稿。衡量的特征之一是“语言表现”。什么意思? 最佳答案 真正的答案:它没有任何意义,或者该演示文稿的作者当时在想什么。 也许它的意思是“执行相对于其他语言具有相同
Go talk 2009 pdf 有评论解释了他们为什么想出 go 语言: No new major systems language in a decade. 系统语言是什么意思? 它是一种应该通过
我现在正在使用 Squeak4.1 学习 SmallTalk。我使用 Squeak by Example 作为教程,在这里我反驳了一个 delema,“Morphic 是由...开发的,用于自编程语言
谁能告诉我如何编译和运行在 ZOMBIE 上编写的程序?例如,如果我编写了以下源代码线以将“hello world”打印到屏幕上,我该如何制作一个 .exe 文件。谢谢! HelloWorld is
我在看帖子Why Language is Important (Why I prefer C#)来自“Dot Net Thoughts”,文章的第一段以以下声明结尾: ...every languag
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 7年前关闭。 Improve t
我正在尝试使用 qTranslate X 制作一个基本的语言切换器,例如: FR | EN 有一个函数可以实现这一点:qtranxf_generateLanguageSelectCode('text'
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 9 年前。 Improv
我正在研究浏览器指纹。在应用程序的 webview 中运行的 js 将通过获取 navigator.language.substr(0,2) == navigator.languages[0].sub
已关闭。这个问题是 not reproducible or was caused by typos 。目前不接受答案。 这个问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-top
"Page description language"、"markup language"、"Page description markup language"有什么区别和关系? 根据他们的 wiki
我正在为 IntelliJ 创建一个自定义语言插件。 我希望新语言的文件可以包含其他语言的文本片段。 我想支持的特定语言是 HTML、JS、CSS 和 SQL。 我还想支持其他自定义语言(即我要为其定
我正在用 mysql 创建一个图书数据库。一本书可以有不同的语言。并且将会有数千本书。 (而且我远不是这个领域的专家,之前只创建过小型和简单的数据库) 1) 只创建一个包含语言列的表并为其创建索引是否
我的网站使用用户可切换的三种不同语言。语言切换由 JavaScript (AngularJS) 在客户端完成。 我在我的网站上使用 reCAPTCHA 2,当用户切换网站语言时需要更改 reCAPTC
我在 Core Image Kernel Language 中有以下函数,我需要在 Metal Shading Language 中等效的东西,但是我对 destCoord 、 unpremultip
“不存在‘编译语言’或‘解释语言’之类的东西。语言实现者选择编写编译器、解释器还是两者之间的任何东西都是实现细节,与语言无关。” 上述说法是否属实? 最佳答案 是的,在最严格的解释中它是正确的。您可以
我是一名优秀的程序员,十分优秀!