Open qishen opened 3 years ago
Ddlog requires that fields with different types in different constructors have different names.
For the other question,
typedef Item = ItemNode{node: Node} | ItemEdge{edge: Edge}
Apologies about brevity and poor formatting. Typing on the phone.
Ddlog requires that fields with different types in different constructors have different names.
By the way, this restriction was borrowed from Haskell and may not actually be necessary in ddlog. We may get rid of it in the future.
Thanks for answering me on your phone! I still don't have time (mainly because of procrastination) to look at Compile.hs
and make changes for the previous PR yet but will try to figure it out and maybe help to remove this field name restriction too.
I was hoping we'd convinced you to use ddlog instead of its internals :). There's unfortunately way too much on my to-do list to help with that feature in the near future.
As for the field name restriction, it's not just a matter of removing the check. We should also make sure it doesn't break type inference or any other part of the compiler, add tests for it, etc.
@ryzhyk You are very close to convincing me to use ddlog directly. I tried my own implementation built upon internals but does not work well. I'm still exploring the potential of ddlog to suit my needs in FORMULA and figure out if they have the exact same semantics despite using the same or similar syntax. One of the great things FORMULA has is nested aggregation (aggregation when certain constraints are satisfied but those constraints also have aggregation inside them) even though it's not used very often. The aggregation in ddlog seems to be highly customizable and I'll do more experiments on it.
If you can't beat 'em, join 'em
Maybe at the end I can just add a feature to ddlog if the feature I need does not exist or a wrapper on top of ddlog. We will see.
Do you guys have a slack channel for ddlog users?
There's a gitter link in the readme. Or feel free to use the discussions section on GitHub.
I'm trying to define a new type that could be either string or integer. My first try is to write
typedef NID = string | u32
but apparently not supported by ddlog so I came up with this onetypedef NID = StrId {nid: string} | NumId {nid: u32}
. The error message I got iserror: graph.dl:10.15-11.1: Field nid is declared with different types
saying theStrId
andNumId
cannot have the same field but it does not make sense since they are different constructors.It could be a bug in the compiler and I also wonder what's the best way to write a union type that represents the union of multiple primitive types?
The other similar question is how to reuse the types defined in the relations if I want a union type like
typedef Item = Node | Edge
whereinput relation Node(id: u32) input relation Edge(src: Node, dst: Node)