Replies: 2 comments 3 replies
-
As we discussed on our community call yesterday we want to slightly change this and move the type/value flag as a suffix of the local name. This has a few benefits:
So the examples would change as such:
|
Beta Was this translation helpful? Give feedback.
-
@AttilaMihaly , @stephengoldbaum , @bekand where did we finally land on this. I'm looking at the I have a use-case for See: |
Beta Was this translation helpful? Give feedback.
-
NodeID - a way to identify Morphir IR nodes
Introduction
Several requirements of the Decorations feature require us to have the ability to refer to specific nodes inside of a Morphir IR. To that end, the following proposal describes "NodeID", a way to refer to Morphir IR nodes in a way that resembles URLs.
Structure
A NodeID can have two slightly different structures depending on if we are refering to modules or definitions (types/values).
"<Package>:<Module>"
"<Package>:<Module>:<localName><.type or .value>#<nodePath>"
, where nodePath is optionalExamples of valid NodeIDs:
"Morphir.Reference.Model:BooksAndRecords"
"Morphir.Reference.Model:BooksAndRecords:deal.type"
"Morphir.Reference.Model:BooksAndRecords:deal.value#1"
Referring to modules
We can refer to modules by their Qualified Name. Types and Values are differentiated with a
.type
or.value
suffix on the last Name before the NodePath part. If no such suffix is present, the ID in question must refer to a moduleFor example:
"Morphir.Reference.Model:BooksAndRecords"
refers to the
Books and Records
module inside theMorphir.Reference.Model
package.Referring to top level types and values
We can refer to Morphir types and values inside modules with their Fully Qualified Name, suffixed with a
.type
or.value
tag. This is necessary, because it is valid (and not unusual) for a Morphir module to contain both a type and a value under the same name (e.g.: ANumber
module containing a type calledInt
and a function calledint
)."Some.Package:SomeModule:foo.type"
would refer to theFoo
type inside theSomeModule
module inside theSome.Package
package. while"Some.Package:SomeModule:foo.value"
would refer to thefoo
function inside theSomeModule
module inside theSome.Package
package.NodePath - Referring to types and values inside other types and values
We can refer to nodes inside top level type or value node with a node path.
A node path is composed of node path steps, which can be either a string when referring to something by name (for example a record field, or function arguments), or an integer, when referring to something by it's position (for example in the case of lists, tuples, pattern match cases, but can also be used for function arguments)
For example if, you have a type defined as:
then a NodeID with the following node path (starting with #)
"Morphir.Package:FooModule:foo.type#tuplefield:1"
would refer to the
String
member of thetupleField
field of theFoo
type.The general rule of thumb would be that when things have a well defined name (e.g.: record fields or arguments of a function definition) they would be referred to with a string, and anything else with an index.
Frequent usecases
...foo#fieldName
refers to the fieldName field of the foo recordsomeType
is declared asa -> b -> c -> d
you will be able to refer toa
assomeType.type#args:0
,c
assomeType.type#args:2
andd
assomeType.type#output
you will be able to refer to the arguments by index (as seen in the previous case), or by specifying the argument name, like
add3.value#args:b
Beta Was this translation helpful? Give feedback.
All reactions