在 OCaml 中,最好始终将 eta 扩展作为万无一失的经验法则吗?
type 'x recordx = { x : int }
type 'y recordy = { y : int }
let rec ok : type n a. n recordx -> a recordy -> int =
fun algebrah x -> ok algebrah x
let rec ok : type a. a recordy -> int =
fun x ->
let go : type b. b recordy -> int = ok in
go x
let rec ok : type n a. …Run Code Online (Sandbox Code Playgroud) Edward Kmett报告了种类推断中的一个错误,这对他的类别库来说非常烦人。
我不知道在 GHC 的某些更高版本中是否已经解决了这个问题。它似乎存在于 8.10.7 和 9.0.2 中。
{-# LANGUAGE PolyKinds #-}
class D a => C (f :: k) a
class C () a => D a
Run Code Online (Sandbox Code Playgroud)
data W f (a :: k) where
MkW :: W Maybe Int -> W f a
Run Code Online (Sandbox Code Playgroud)
如何获取有关此问题的信息(例如:它是否会得到解决)?
我有一个令人费解的例子,下面的“ok”,我完全不明白。
module File1_intf = struct
type type1 = { nat : int }
module type Intf = sig
type nonrec type1 = type1
end
end
module File1 : File1_intf.Intf = struct
include File1_intf
end
module File3 = struct
open File1
let ok : type1 -> type1 = fun { nat } -> { nat = 0 }
let ko { nat (*Unbound record field nat*) } = { nat = 0 }
end
Run Code Online (Sandbox Code Playgroud)
我期望“未绑定记录字段”,但我想知道为什么添加类型装饰会将字段“nat”纳入范围。
我不太清楚为什么数据框对象不会更新
d <- data.frame(titi=c(0))
(function(dataset) {
dataset[["toto"]] <- 1;
print(names(dataset)) #has "toto" and "titi"
})(d)
print(names(d)) # no has "toto", only "titi"
Run Code Online (Sandbox Code Playgroud)
这里发生了什么 ?
我有一个解决方法,因为在我的代码中我也捕获变量并更新捕获的<<-,但我想知道机制.
我知道一般的变异等危险.我只是不明白这里的机制.
编辑
虽然这似乎是一个共识,这是一个语言级别的功能,我不遵循这个论点,好像我使用一个紧密的结构,数据表,它可以变异:
d <- data.table(titi=c(0))
(function(dataset) {
dataset[,toto:=1]
print(names(dataset)) #"titi" "toto"
})(d)
print(names(d)) #"titi" "toto"
Run Code Online (Sandbox Code Playgroud)