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
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.
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
The text was updated successfully, but these errors were encountered:
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.
Attaching metadata to a type
This example shows a new capability that is attaching metadata to type expressions
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 withName
it needs to be aString
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 withName
it needs to be aString
but also needs to have a metadata attached to that at least has a field calledid
with value1
In order to work with our type system we have two operators
is
andas
. Theis
operator returnstrue
if avalue
is accepted by thetype
.The
as
operator tries to transform thevalue
to a new value that is conforming with the given type such that the result(x as T) is T
should either betrue
or fail, but shouldnever
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 attachid : 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 theas
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
In this example we see that json schema can add
title
and adescription
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
anddescription
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
The text was updated successfully, but these errors were encountered: