HomeForumSourceResearchGuide
Sign in to reply to forum posts.
Coming up with data type agnostic function signatures

Hello again,

As previously mentioned, I'm trying to build an extensible and data type agnostic extension to the CSV functionality and I have the following questions and ideas and things I've tried:

1) Can a primitive type be assigned to Data? I want to pass an array of primitives (the new column or row) but that array could be either ints or decs and I don't know which at compile time. So how do I set up the function signature?

2) I thought the problem solved by the ADT library, like this: "void add(store Data item)" - this is from adt.List. However, it doesn't compile when I try to use store.

3) Do I wrap primitive types in Data? Like String?

4) Do I provide a bunch of the functions for different primitive data types?

5) Do I do it with optional parameters and set only the one I'm interested in?

6) Do I serialise Data and then deserialise it based on a Type provided in the function?

I went with the idea of wrapping primitive data types in Data, however, this causes another issue with assignment between variables with different sizes. I'll create a separate post for this issue.

Again, I'm open to suggestions!

Many thanks,

Sava

HI Sava,

You can't automatically assign a primitive type to a Data. The store qualifier is for a different purpose -- it's to indicate whether or not a function's implementation intends to keep a given reference type in its global state. This is a different topic, but this is necessary for stateful side effect analysis for sound runtime adaptation support.

If I understand correctly you probably are looking to design an interface something like this:

interface CSVColumn {
   CSVColumn(char path[])
   void addColumnInt(char heading[], int values[])
   void addColumnDec(char heading[], dec values[])
   }

I think the above would be sufficient since you only really need to support int and dec types here. Your idea of using optional parameters would also work well, though! i guess there you'd have list one addColumn() function which perhaps always takes a heading, and optionally takes an int or dec array?

I think this is a scenario in which there isn't an existing precedent in the standard library, so it's really up to you to choose the design you think is best :-)

Barry

Hello,

Here is the latest version of my work:

https://github.com/savakazakov/CSVUtilExtension

I would love to get some opinions on matter from more experienced Dana users.

Many thanks,Sava

Hi,

I just had a chance to look at this. I think you have the start of something really quite interesting here!

I would simplify it a bit to make it easy for regular int[] and dec[] arrays, plus possibly char[]-based columns (via String[]).

I also thought it might be a really useful addition to have a function which reads in the entire CSV file into a Data`. People could then combine this quite easily with the stats.chart stuff to make graphs.

Thanks for sharing!

Hi Sava :-)

I totally agree with the above comments, and the way this is implemented is really cool :-)

With maybe a bit more expansion it would be great to see something like this added to the standard library.

jess

Hello,

Thanks for the suggestions. I noted those and some give to me by Barry Porter and I'll fix them in the coming days. Moreover, I have some ideas for a slightly different function signatures and I'd really appreciate your input on what you think fits best given the use case.

Once again, thank you very much!

Sava