On 26 February 2015 at 23:04, Keean Schupke <[email protected]> wrote:
> There seems to be a need for an extensible datatype:
>
> data Thing = Link {next :: Pointer}
> | Ageable {Link | age :: Int}
> | ObjectHeader {Ageable | id :: Int}
>
> etc...
>
I am not sure if silence means everyone likes this idea, or has dismissed
it already, but in terms of explanation, a standard datatype like this:
data Test = A {prop1 :: Int, prop2 :: Float} | B {prop1 :: Float, prop 2 ::
Int}
Translates into a 2 layer C++ inheritance hierarchy:
struct Test {
enum tag {a, b} tag;
};
struct A : public Test {
int prop1;
float prop2;
};
struct B : public Test {
float prop1;
int prop2;
};
So with extensible the extensible records example above you get:
struct Thing {
enum tag {link, ageable, object_header} tag;
};
struct Link : public Thing {
Pointer next;
};
struct Ageable : public Link {
int age;
};
struct ObjectHeader : public Ageable {
int id;
}
I realise you do not get separate types like this, but the following would
fix that:
data Link = Link {next :: Pointer}
data Ageable = Ageable {Link | age :: Int}
data ObjectHeader = ObjectHeader {Ageable | id :: Int}
data Thing = L Link | A Ageable | OH ObjectHeader
Keean.
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev