How to declare a member entry with a shared list of entries in F #

I am stuck with how the general list of posts goes. I want to do this:

type TabularData<'T>= array<'T> type Table = {title:string; data:TabularData<'T>} //This of course not work type Cpu = { name:string; load:int; } type Memory = { name:string; load:int; } //F# not let me pass CPU or Memory 

I want to create any list of records of any type and pass it for serialization in json

PD: Additional information about the problem.

I do not want to add the main problem. Using generics, it has spread to other functions. Therefore, I need to mark EVERYTHING with a common signature, so that you can be more general and say: "Can I have any entries here?"

+5
source share
1 answer

You also need to create a generic table type:

 type Table<'T> = {title:string; data:TabularData<'T>} 

And since your two records have the same fields, you can use Cpu.name to explicitly say that you are creating a table with CPU values:

 { title = "hi"; data = [| { Cpu.name = "test"; load = 1 } |]} 
+7
source

All Articles