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

Sorting attributes with constructed types #316

Open
farzadbekran opened this issue Oct 27, 2021 · 3 comments
Open

Sorting attributes with constructed types #316

farzadbekran opened this issue Oct 27, 2021 · 3 comments

Comments

@farzadbekran
Copy link
Contributor

Currently attempting to sort a relation by an attribute that has a constructed type throws an AttributeNotSortableError. This is really limiting, since even a simple Maybe type becomes unsortable as well.

I think we need a solution that behaves like sortBy which takes an AtomFunction or maybe something like a ValueExtractionExpr (which behaves like a RelationalExpr) and provides the value on which the sort should be done.

Any Ideas on this?

@agentm
Copy link
Owner

agentm commented Oct 27, 2021

I can see how that would be annoying indeed. Thus far, I've been avoiding implementing typeclass support at the Atom level, but it might be required. It doesn't make sense (to me, at least) that all Atoms must be sortable.

We'll need to implement some basic typeclass support. Are there other typeclasses that would make sense to have as built-ins?

@farzadbekran
Copy link
Contributor Author

I'm not sure how the typeclass would work but let's say this is how it would work for these types for example:

  • Maybe a: Just a values first, then Nothings. While Just as are sorted themselves by as. How as are sorted should be determined by the typeclass for as.
  • Either a b: Right bs first then Left as, while Rights and Lefts are sorted based on their values.
  • Generally types would provide their own compare function or a way to extract a value from the atom that implements Ord typeclass.

These are my initial thoughts on how it would work. Hope it makes sense.

@farzadbekran
Copy link
Contributor Author

As the user, maybe I could extend the relation and put a sortable atom inside an attribute using an atom function, sort on it and remove it later. But a db level solution would be preferred.

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

No branches or pull requests

2 participants