【发布时间】:2010-06-07 20:40:40
【问题描述】:
我刚刚将我的原型元组升级为记录。有朝一日,它可能会成为一堂真正的课。同时,我想翻译这样的代码:
type Example = int * int
let examples = [(1,2); (3,4); (5,6)]
let descs = Seq.map (fst >> sprintf "%d") examples
到这里:
type Example = {
Field1 : int
Field2 : int
Description : string
}
let examples = [{Field1 = 1; Field2 = 2; Description = "foo"}
{Field1 = 3; Field2 = 4; Description = "bar"}
{Field1 = 5; Field2 = 6; Description = "baz"}]
let descs = Seq.map Description examples
问题是当我声明示例记录时,我希望得到一个函数Description : Example -> string,但我没有。我已经四处寻找并尝试了类的属性,但这也不起作用。我只是在文档中遗漏了一些东西,还是必须手动编写高阶访问器? (这就是我现在使用的解决方法。)
【问题讨论】:
标签: f# properties record accessor higher-order-functions