How are types encoded into the IR. #53
-
In the What does the data format look like? section we have the following example:
In Morphir's data format this would translate into something like this:
Can you show an example of how the type info for this would be represented in the IR? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Maybe it should be mentioned in that page that this is a simplified JSON just to illustrate the concept. The real JSON will be much more complex. For example, the above expression will translate to this JSON (it's too big with proper indentation so I included the compact version here): ["apply",["reference",null,[[["morphir"],["s","d","k"]],[["basics"]],["float"]],[]],["apply",["function",null,["reference",null,[[["morphir"],["s","d","k"]],[["basics"]],["float"]],[]],["reference",null,[[["morphir"],["s","d","k"]],[["basics"]],["float"]],[]]],["reference",["function",null,["reference",null,[[["morphir"],["s","d","k"]],[["basics"]],["float"]],[]],["function",null,["reference",null,[[["morphir"],["s","d","k"]],[["basics"]],["float"]],[]],["reference",null,[[["morphir"],["s","d","k"]],[["basics"]],["float"]],[]]]],[[["morphir"],["s","d","k"]],[["basics"]],["multiply"]]],["variable",["reference",null,[[["morphir"],["s","d","k"]],[["basics"]],["float"]],[]],["quantity"]]],["variable",["reference",null,[[["morphir"],["s","d","k"]],[["basics"]],["float"]],[]],["unit","price"]]] You can also use this page to generate the IR for any Elm models. It shows a visual version of the IR but there's a newer version that can show the JSON too (I have an open PR to publish it). In general the best way to understand the JSON is to look at the Elm API for the IR together with the standard Morphir-to-JSON mapping. The JSON is a direct serialization of the Elm data structures using that standard mapping. |
Beta Was this translation helpful? Give feedback.
-
To elaborate a bit more: You will notice that the IR JSON contains type information on every value node. This is because type information is used in many of our backends but it will make your life much more difficult when you are building a frontend. To avoid that I think we should expose the type inference tooling separately so that you can focus on creating the IR without type information in your frontend and then reuse the type inference we already have in the Elm tooling to enrich it with types. That would also be a nice way to check the validity of the IR you created. |
Beta Was this translation helpful? Give feedback.
Maybe it should be mentioned in that page that this is a simplified JSON just to illustrate the concept. The real JSON will be much more complex. For example, the above expression will translate to this JSON (it's too big with proper indentation so I included the compact version here):