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

Data type guards #42

Open
3 tasks
jackfirth opened this issue Mar 3, 2019 · 3 comments
Open
3 tasks

Data type guards #42

jackfirth opened this issue Mar 3, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@jackfirth
Copy link
Owner

jackfirth commented Mar 3, 2019

Analogous to struct-guard/c, there should be xxx-guard/c contract combinators for use with each kind of type in rebellion/type. They should provide APIs similar to the constructors of the kind of types they're meant for. Subtasks:

@jackfirth jackfirth added the bug Something isn't working label Mar 3, 2019
@jackfirth jackfirth changed the title There's no documented way to attach contracts to tuple descriptors Add support for guards in type descriptors Aug 13, 2019
@jackfirth jackfirth changed the title Add support for guards in type descriptors Support guards in type descriptors Aug 13, 2019
@jackfirth jackfirth added enhancement New feature or request and removed bug Something isn't working labels Aug 13, 2019
@jackfirth jackfirth added this to the Datatypes Alpha Release milestone Aug 13, 2019
@jackfirth jackfirth added the needs api design The public API changes for this feature aren't yet designed label Sep 4, 2019
@jackfirth
Copy link
Owner Author

jackfirth commented Sep 10, 2019

Notes on API designs currently being explored:

  • The guard functions should accept values for each field and an extra value with information about the type, so the guard function can raise errors that use the type's name and field names.

  • The type information should usually be given first, then the guard should return a function that accepts the field values. This allows a guard to make assertions about the shape of the type. Tuple guards (Guards for tuple types #203) and record guards (Guards for record types #204) both need this feature, but wrapper guards (Guards for wrapper types #202) don't.

  • Currently, guards are just plain functions. But maybe they should be functions wrapped by a struct, to make it easier to check first-order properties about them and to make the guard APIs easier to work with.

  • Guards are most important for types that are usually used as plain bags of data (wrappers, tuples, records), rather than types that seal away some opaque fields (reference types). The former are much higher priority than the latter.

  • Singleton type guards seem pointless.

  • Guards ought to be able to normalize and convert field values. This makes them slightly more powerful than plain chaperone contracts, since they don't have to return equal? values. But they're not applied on field accesses, only on instance construction. Additionally, this normalization should be idempotent.

  • Guards ought to be able to check constraints across multiple fields. Example: a bounds tuple type with a min field and a max field should enforce that min <= max. This might require a dependent contract combinator, or maybe there's room for some sort of "multicontract" API.

@jackfirth jackfirth changed the title Support guards in type descriptors Data type guards Sep 10, 2019
@jackfirth
Copy link
Owner Author

Combined with #177, this would allow deleting a ton of the boilerplate associated with defining and providing a non-generic data type. Candidates within rebellion include:

  • Media and media types rebellion/media
  • Octet streams rebellion/media/application/octet-stream
  • Points rebellion/point
  • Text media rebellion/media/text/plain
  • Web graphs rebellion/web-graph
  • Web links rebellion/web-link

@jackfirth
Copy link
Owner Author

The API for this seems mostly designed for now, see the three subtasks.

@jackfirth jackfirth removed the needs api design The public API changes for this feature aren't yet designed label Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant