Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generic Data Structure Description Language

I am wondering whether there exists any declarative language for arbitrarily describing the format and semantics of a data structure, that can be compiled to a specific implementation of that structure in any of a set of target languages. That is, something like a generic data definition language but geared toward describing arbitrary data structures such as vectors, lists, trees, etc., and the semantics of operations on those structures. I ask because I had an idea for a feasible implementation of this concept, and I'm just wondering whether it's worth it, and, consequently, whether it's been done before.

Another, slightly more abstract question: is there any real difference between the normative specification of a data structure (what it does) and its implementation (how it does it)? More specifically, should separate implementations of the same requirements be considered different structures?

like image 458
Jon Purdy Avatar asked Apr 03 '10 03:04

Jon Purdy


People also ask

What is a generic data structure?

An Introduction to Generic Data Structures Each data structure is a container that holds a particular data type. Operations changes from data type to data type, for example, how you add two integers is not the same as how you “add” two tables.

How do you describe data structures?

A data structure is a specialized format for organizing, processing, retrieving and storing data. There are several basic and advanced types of data structures, all designed to arrange data to suit a specific purpose. Data structures make it easy for users to access and work with the data they need in appropriate ways.

What is a generic data structure in C?

In C, void* is a generic pointer type – it is up to the user to interpret the data as an apporpriate type. This is usually the go to way of implementing generics. Basically, we have a data structure of pointers. We don't care about the type, we just store the pointers and give the pointers back to the user.

Why is generic data structure important?

Data structures give shape to our data without having to be aware of what the data is. Making these structures generic allows us to reuse the shape for all sorts of values, significantly reducing the amount of code we need to write.


1 Answers

If you felt like it, a combination of XML with XSLT could describe a data structure, and provide a matching definition in essentially any language if your choice. I've never tried to prove it formally, but my first guess would be that S-expressions are a superset of XML (modulo syntactical differences).

At least in theory, yes there are (or at least can be) differences between a description of what a data structure does, and how it does it. For an obvious example, you could describe a generic mapping from keys to values, which could use an implementation based on hash tables, skip lists, binary search trees, etc. It's mostly a question of describing it at a high enough level of abstraction to allow differences in the implementation. If you include too many requirements (complexity, ordering, etc.) you can pretty quickly rule out many implementations.

like image 189
Jerry Coffin Avatar answered Sep 28 '22 18:09

Jerry Coffin