egraphs-good / egglog

egraphs + datalog!
https://egraphs-good.github.io/egglog/
MIT License
459 stars 54 forks source link

Pair / Tuple built-in type? #393

Closed AzizZayed closed 1 month ago

AzizZayed commented 4 months ago

I see that there are built-in types like Vec, Map and Set. Is there a pair or tuple built-in type? The usage would be like

(sort ITuple (Tuple i64 i64))
(sort SITuple (Tuple String i64))
yihozhang commented 4 months ago

Not currently! For now you have to write your own tuple datatype:

(datatype PairI64I64 (Pii i64 i64))
(function fst (Pairi64I64) i64)
(rule ((Pii a b)) ((set (fst (Pii a b)) a)))
...

Note that implementing pairs as built-in container types also has its limitations. For example, you cannot have (Pii a b) as part of the query if it's implemented as a built-in container.

saulshanabrook commented 4 months ago

Note that with user defined generics a pair type could be written more easily and re-used without having to redefine the rewrites for every type of pair: https://github.com/egraphs-good/egglog/issues/386