Generate enums in csv type provider
If a column is infered as string, and there are many repeated values, it's probably an enumeration, so we could generate an enum. If the inference geets it wrong, we could always override (#19). We could use something like (number of distinct values / number of rows) < 0.2 to trigger this
This is an interesting thought. Is it actually possible to generate enums in a type provider?
There's no ProvidedEnum in ProvidedTypes.fs, but maybe it's possible to add it. It's not an F# only type, so I'm guessing it it should be possible
http://stackoverflow.com/questions/15174637/how-to-generate-enums-in-a-f-type-provider
Cool, it would make sense to have this in. The only sad things is that it will require fully qualified access. But even then, this looks pretty good to me:
type Foo = CsvProvider<....>
[ for r in Foo().Data do
if r.Bar = Foo.ColumnName.CaseName then yield r.Other ]
(I think we probably do not need to hide the enums in DomainTypes - that would make them hard to discover.)
Actually, the CsvProvider doesn't have a DomainTypes right now, because it only has one inner type, unlike JsonProvider & XmlProvider which can have multiple. I think we should keep it that way
If this is an ongoing requirement, I can take this on. The above discussion should give me enough detail to implement this feature.
That would be great, though I'm under the impression that it's only possible to make enums work in generated TPs. In any case, it needs investigation to confirm that. We have another item to switch to the generated model
Ah thanks - I hadn't noticed that. I'll do some research first and report back. If necessary we can shelve until we switch to generated.
Or you could move CSV to generated as part of this :)
Of course - actually I was trying to find that item to see if it was up for grabs - I didn't spot it though?
It's here: https://github.com/fsharp/FSharp.Data/issues/134
nice point! is there any news on this one? seems like a pretty cool functionality