f#-data

F# XML Type Provider Common Elements

偶尔善良 提交于 2019-12-10 10:15:59
问题 XSD specifications for XML files can share common elements. If I have several XML files that share a common element, is there a way to extract the common element without repeating the code for each XML file type? For example: There are a number of XML files defined via XSD, with a common description element, but different content structures elsewhere. The description has subelements with things like author, date, etc. When I create a type provider for each of the XML files, the types are

FSharp.Data.JsonProvider - Getting json from types

一笑奈何 提交于 2019-12-10 03:45:36
问题 The FSharp.Data.JsonProvider provides a means to go from json to an F# type. Is it possible to go in the reverse direction i.e. declare an instance of one of the types created by FSharp.Data.JsonProvider, set the field values to be what I need, and then get the equivalent json? I've tried things like this, type Simple = JsonProvider<""" { "name":"John", "age":94 } """> let fred = Simple( Age = 5, // no argument or settable property 'Age' Name = "Fred") 回答1: The latest version of F# Data now

Can a Type Provider be passed into a function as a parameter

痞子三分冷 提交于 2019-12-08 21:09:04
问题 I am learning F# and the FSharp.Data library. I have a task which I need to read 20 CSV files. Each file has different number of columns but the records share the same nature: keyed on a date string and all the rest of the columns are float numbers. I need to do some statistical calculation on the float format data columns before persist the results into the database. Although I got all the plumbing logic working: read in the CSV via FSharp.Data CSV type provider, use reflection to get the

MissingMethodException when running a unit test that uses FSharp.Data

≯℡__Kan透↙ 提交于 2019-12-08 19:18:38
问题 I have a NUnit unit test that is written in a normal F# library but targets F# code in a Portable Class Library. When I run this test (in Visual Studio 2013), I get the following exception: Result Message: System.MissingMethodException : Method not found: 'Microsoft.FSharp.Control.FSharpAsync`1<System.IO.TextReader> FSharp.Data.Runtime.IO.asyncReadTextAtRuntime(System.Boolean, System.String, System.String, System.String, System.String)'. This is what I have in my app.config in the Portable

F# Data Type Provider - Create with string variable

一个人想着一个人 提交于 2019-12-08 08:09:55
问题 In F# I have the following bit of code [<Literal>] let fname=fstFile.FullName.ToString() type genomeFile = CsvProvider<fname> Where fstFile is an instance of the FileInfo class. However, this fails with: This is not a valid constant expression or custom attribute value And I can't seem to create the type without an actual hard coded string. Does anyone know how to fix this? 回答1: The parameter to the CSV type provider needs to be a constant, so that the types can be generated at compile-time

Type provider for MySql

淺唱寂寞╮ 提交于 2019-12-07 17:23:15
问题 I've been searching for an example on how to connect to a MySql database and use F# type providers but I could not find anything online. Can anyone give me a clue? What - if any - extra packages do I need? Do I use SqlDataConnection or SqlEntityConnection . Excuse my ignorance but I'm totally lost. Any and all help is appreciated. I love the idea of type providers and have a fair amount of experience with functional programing but it's the setup around this that gets me. 回答1: I don't think

F# XML Type Provider Common Elements

偶尔善良 提交于 2019-12-06 02:57:39
XSD specifications for XML files can share common elements. If I have several XML files that share a common element, is there a way to extract the common element without repeating the code for each XML file type? For example: There are a number of XML files defined via XSD, with a common description element, but different content structures elsewhere. The description has subelements with things like author, date, etc. When I create a type provider for each of the XML files, the types are different, so if I only want to extract the description section out of each, the code has to be copy pasted

Type provider for MySql

杀马特。学长 韩版系。学妹 提交于 2019-12-06 01:39:30
I've been searching for an example on how to connect to a MySql database and use F# type providers but I could not find anything online. Can anyone give me a clue? What - if any - extra packages do I need? Do I use SqlDataConnection or SqlEntityConnection . Excuse my ignorance but I'm totally lost. Any and all help is appreciated. I love the idea of type providers and have a fair amount of experience with functional programing but it's the setup around this that gets me. I don't think there is out-of-the box type provider that would work with MySQL at the moment. However, Ross McKinlay has

Using F# JsonProvider within a portable class library fails

断了今生、忘了曾经 提交于 2019-12-05 20:11:40
I'm trying to use the JsonProvider and I'm getting the following error when I call a function on it: System.TypeInitializationException was unhandled Message: An unhandled exception of type 'System.TypeInitializationException' occurred in PortableLibrary1.dll Additional information: The type initializer for '<StartupCode$PortableLibrary1>.$PortableLibrary1' threw an exception. I have a basic console application as follows: module Pinit = open FSharp.Data type JsonT = JsonProvider<"""..\myFile.json"""> let doc = JsonT.Load("""..\nyFile.json""") let result = doc.GeneratedAt [<EntryPoint>] let

How to create a CSV file and write data into in f#

…衆ロ難τιáo~ 提交于 2019-12-04 11:32:48
问题 How can i can i create a csv file in f sharp and write the following record type in it? type test = { G:array<double>; P:array<double>; GG:array<double>; PP:array<double> } let table = [for x in 0..(Un0.Length - 1) -> let b = Un0.[x] in if b=0.0 then {G=0.0; P=0.0; GG=0.0; PP=0.0} else {G=G_0.[x]/b; P=P0.[x]/b; GG=G0.[x]/b; PP=PP0.[x]/b}] 回答1: To record in .csv is not necessary to use F# Data. I changed the definition of test and added some values so that you can compile: type test = { G