Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADT Constructors' ordinal value is according to alphabetical order, not declaration order #2499

Open
AdiHarif opened this issue Jul 22, 2024 · 2 comments

Comments

@AdiHarif
Copy link

I was trying to define functors that receive ADTs as parameters and couldnt find any documentation about it.

From the tests in this repo i figured that when unpacking an ADT value in the functor implementation, the first value of the returned array is the constructors ordinal number (given that there is at least one parameterized constructor). I assumed that this ordinal value is according to constructors' declaration order, however found out that it is according to alphabetical order.

Is this by design? to be honest i find it somewhat not intuitive...

Example Souffle program:

.functor get_ctor_ordinal(v: T): unsigned stateful

.type T =
      B {}
    | A {}
    | C { x: unsigned }


.decl R(v: T, o: unsigned)

R($B(), @get_ctor_ordinal($B())).
R($A(), @get_ctor_ordinal($A())).
R($C(1), @get_ctor_ordinal($C(1))).

.output R

Functor Implementation:

RamDomain get_ctor_ordinal(SymbolTable* symbolTable, RecordTable* recordTable, RamDomain value) {
    const RamDomain* record = recordTable->unpack(value, 2);
    return record[0];
}

Output:

---------------
R
v       o
===============
$B      1
$A      0
$C(1)   2
===============
@quentin
Copy link
Member

quentin commented Jul 22, 2024

Hi, a good explanation of ADT representation is still missing from the docs.

You can refer to #2055 (comment)

And yes, ADT branches are indexed by alphabetical order.

@AdiHarif
Copy link
Author

AdiHarif commented Jul 22, 2024

Thanks!
Is there a reason for indexing these branching alphabetically?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants