【问题标题】:could this be a F# 6 indexer bug?这可能是 F# 6 索引器错误吗?
【发布时间】:2021-12-27 22:00:26
【问题描述】:

让我们考虑一下这段代码:

type T =
    {
        a: int
    }    

let d =
    [
        "a", [{a = 0}; {a = 1}; {a = 2}]
        "b", [{a = 3}; {a = 4}; {a = 5}]
    ] |> Map

如果我想用 a = 0 访问数据:

d.["a"].[0].a  <- works
d["a"].[0].a   <- now works with F#6
d["a"][0]      <- returns {a = 0}

但是

d["a"][0].a    <- typecheck error This value is not a function and cannot be applied.

如果我将表达式括在括号中:

(d["a"][0]).a  <- it works

这是预期的,还是 F#6 解析错误?

【问题讨论】:

  • 我同意这看起来很可疑。
  • 如果没有,我认为您应该在这里创建一个问题:github.com/dotnet/fsharp。在我看来它应该可以工作。
  • @Justanothermetaprogrammer 我做了

标签: f#


【解决方案1】:

最后,这样做是出于兼容性原因;查看 Don Syme 的回复:

https://github.com/dotnet/fsharp/issues/12549#event-5840475607

已发布允许此表示法的请求,似乎已获批准。

https://github.com/fsharp/fslang-suggestions/issues/1109

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多