Here is a snippet that demonstrates what I'll talk about well:
open FsCheck
open FsCheck.Gen
open FSharp.Data
type Test = JsonProvider<"""{"collection": [ { "Name": "Rob", "Age": 3 } ] } """>
let testGen () =
gen {
let! name = Arb.generate<string>
let! age = Arb.generate<int>
let colObj = Test.Collection(name, age)
return Test.Root([|colObj|])
}
let specialTestGen () =
gen {
let! test = testGen ()
let item = test.Collection.[0]
let foo = item.Name
let changedItem = {item with Name = "Chris"}
return {test with test.collection = [|changedItem|]}
}
I'm trying to make a gen with some fields gen'd constantly. I can assign out in to foo the collection instance's name, but for some reason I can't construct another slightly modified version of the stuct. It tells me item has no property called Name, when clearly on the line before it, it does. Can I not use the "with" syntax this these libraries for some reason?
Type providers can only provide ordinary .NET types right now, not F# records and discriminated unions. The
{x with ...}
syntax is only for F# records.