You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Couldn't match type ListTable Result (SomeData Result) with [SomeData Result] #321
I encountered this type error recently while trying to store a ListTable within one of my table schemas, defined sort of like
data SomeTable f = SomeTable
{ someId :: Column f SomeId
, nested :: ListTable f (SomeData f)
}
This was kind of confusing, as I'd assumed these were the same types. I was still able to get my code to work, simply by splitting up the SomeTable data type into its individual fields after selecting it with each, and returning them in a tuple, rather than in the SomeTable constructor.
My main question is is this working by design, or something preventing type inference, or something else? I've used many plenty to returned nested tables, and never encountered any issues, which is why I thought the types were equivalent. Though this is the first time I've ever stored a ListTable within a schema, which seems relevant, since it's only when I tried to work with a SomeTable Result that the ListTable Result stopped being a list.
If you want to store a List table in a Rel8able, try using HList. That has special support for using ListTable with Expr and [] with Result. Does that help?
Yeah, that seemed to work, though I'm still left wondering why tupling the ListTable didn't experience the same problem. But I suppose it's not really important as long as I know how to avoid it. Thanks.
It's unfortunately very difficult to make what you want work. If we have a Query (ListTable expr a), we really want the result here to be a [a'] - having to work through some other list type would (imo) kinda suck. So this means we need ListTable to select into []. But in your record, that ListTable appears without any wrapping, which means we can't make the same mapping. This is why it tries to produce a ListTable Expr, but that's contradictory (because a Foo ExprRel8able has to select to Foo Result). So unfortunately this is all rather "due to technical reasons", which I never like as an answer... But this is the best solution we know about for now!
I guess I'll close this then, I did find the stuff in the documentation in HList mentioning storing it in tables. I might work on adding examples of things like this to the cookbook.
Activity
ocharles commentedon Apr 17, 2024
If you want to store a List table in a Rel8able, try using HList. That has special support for using ListTable with Expr and [] with Result. Does that help?
abigailalice commentedon Apr 17, 2024
Yeah, that seemed to work, though I'm still left wondering why tupling the
ListTabledidn't experience the same problem. But I suppose it's not really important as long as I know how to avoid it. Thanks.ocharles commentedon Apr 17, 2024
It's unfortunately very difficult to make what you want work. If we have a
Query (ListTable expr a), we really want the result here to be a[a']- having to work through some other list type would (imo) kinda suck. So this means we need ListTable to select into[]. But in your record, thatListTableappears without any wrapping, which means we can't make the same mapping. This is why it tries to produce aListTable Expr, but that's contradictory (because aFoo ExprRel8ablehas to select toFoo Result). So unfortunately this is all rather "due to technical reasons", which I never like as an answer... But this is the best solution we know about for now!abigailalice commentedon Apr 20, 2024
I guess I'll close this then, I did find the stuff in the documentation in
HListmentioning storing it in tables. I might work on adding examples of things like this to the cookbook.