I just upgraded my prototyping tuple to a record. Someday it may become a real class. In the meantime, I want to translate code like this:
type Example = int * int
let examples = [(1,2); (3,4); (5,6)]
let descs = Seq.map (fst >> sprintf "%d") examples
to this:
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
The problem is that I expected to get a function Description : Example -> string
when I declared the Example record, but I don't. I've poked around a little and tried properties on classes, but that doesn't work either. Am I just missing something in the documentation or will I have to write higher-order accessors manually? (That's the workaround I'm using now.)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…