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

Attaching Metadata Proposal "Draft" #42

Open
machaval opened this issue Oct 27, 2022 · 0 comments
Open

Attaching Metadata Proposal "Draft" #42

machaval opened this issue Oct 27, 2022 · 0 comments

Comments

@machaval
Copy link
Contributor

Attaching Metadata

Abstract

We are proposing adding a new operator <~ that will be used to attach metadata to any value (types included). The syntax is
<valueB> <~ <objectA> and it reads attaching objectA to valueB. The arrows points the direction how the attching flows.

Examples

Attaching metadata to a value

This examples shows the new syntax without the need to specify any Type.

{name: "User"} <~ {class: "acme.User"}

Attaching metadata to a type

This example shows a new capability that is attaching metadata to type expressions

type T =  String <~ {label: "A Type"}

Thinking process

To understand how we reach to this first read [https://github.com//issues/40](Metadata Schema Problem)

Metadata

We define metadata as any additional information attached to a value that doesn't affects its identity. And by that we mean that if given any value
A and B are equal then if we attach metadata to A and we call it A' then A == A' == B. So we can define that a value is formed by the value it self
and a metadata attached to it.

Type system

Our type system is a Structural Type system. This means that values and types are decoupled. A value is just that and a type are just constrain rules.

For example: type Name = String here express that a value to be conforming with Name it needs to be a String but we can also express more complex stuff using algebraic types (union, intersection, record, literal types). We also support adding constrains to the metadata part of the value. type Name = String {id: 1} here express that a value to be conforming with Name it needs to be a String but also needs to have a metadata attached to that at least has a field called id with value 1

In order to work with our type system we have two operators is and as. The is operator returns true if a value is accepted by the type.
The as operator tries to transform the value to a new value that is conforming with the given type such that the result (x as T) is T should either be true or fail, but should never return false.

Attaching metadata

Currently the only way we have to atach metadata to a value is by using the as operator. For example to attach id : 1 to a string value we need to do "test" as String {id: 1} this has always been very hard for people to understand because the main perpouse of the as is to change types and using the technique to attach metadata looks more like a workarround than something intentional.

Other problem that we found was that we don't have a way to attach metadata to a Type. This is not allowing us to represent additional information that other type system have to be encoded and persisted.

For example json schema

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "title": "Object title",
  "description": "Object description",
  "properties": {
    "number": {
      "type": "number",
      "title": "Number title",
      "description": "Number description"
    }
  },
  "additionalProperties": false
}

In this example we see that json schema can add title and a description and we currently don't have a way to represent this in our language.

This shows the gap that we currently have that we don't have a way to attach metadata to types as title and description are not constrains but rather additional information.

Syntax

Though we are trying to avoid adding new operators we tried to have a simple and short way to express this.

The sintax is also consistent with the << append and prepend >> of elements in the array where the arrows point to the value being applied.

Open questions

Are we going to support value expressions in the right part of the attach metadata

var a = {id: 1}
---
"" << a
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

1 participant