compossible icon indicating copy to clipboard operation
compossible copied to clipboard

Better set operations

Open cvogt opened this issue 9 years ago • 5 comments

currently there is & which is a union operator on the key value pairs. The default should probably rather be a disjoint union that throws a type error in case of overlap.

Overview of useful operators that should be implemented

  • Union, rhs fields replace lhs fields (currently implemented as &)
  • Disjoint Union, e.g. |
  • Intersection, e.g. &
  • Minus, e.g. r \ (select field1 & field2) or r(remove field1 & field2) or
  • Recursive Union, struct fields merge, non-struct fields replace

cvogt avatar Feb 10 '15 18:02 cvogt

Overlap is sometimes perfectly valid. Requiring users to rename their records could be a too big burden. Maybe you can introduce a default scheme for resolving conflicts.

vjovanov avatar Feb 11 '15 10:02 vjovanov

@vjovanov I am thinking to have one operator that simple overrides and one that fails on conflicts. I don't think I like automatic conflict resolution that alters the structure. Maybe if it is demanded at some point. For now I am just planning to add a way to actually RENAME fields: https://github.com/cvogt/records/issues/5

cvogt avatar Feb 11 '15 22:02 cvogt

That is a good strategy, if users need it you can always build on top of it. In scala-records we will use the structural types for this.

vjovanov avatar Feb 11 '15 22:02 vjovanov

@vjovanov for what exactly? Renames? How would the syntax be?

cvogt avatar Feb 11 '15 22:02 cvogt

Yep for renames, although they would be rather nested records. If you merge two records the collided fields would be in the nested record:

Rec { 
  lhs: Rec { collidedField: String }
  rhs: Red { collidedField: String }
  // .. the rest
} 

vjovanov avatar Feb 12 '15 10:02 vjovanov