F# Higher-order property accessors
- by Nathan Sanders
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 field1s = Seq.map (fst >> printfn "%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 field1s = 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.)