Writing generic function in F# to save csv files

时间:2016-10-20 19:47:40

标签: f# type-providers f#-data

I have a requirement to read a csv file and generate several different projections of the data from save to files. I'm using CsvProvider to read the file and then map the data into other CsvProviders which I save to disk. Currently I have seperate save functions to save each of these projections. I'm wondering if I could create a generic saveCsv function like this?

let saveCsv<'a when 'a :> CsvProvider> (csvType:'a) fileName data =
    let csv = new csvType(data)
    csv.Save(fileName)

I can't seem to get the type constraint correct and also how do I new up a instance of the csvtype?

0 个答案:

没有答案