Adding fixed precision integer types to Morphir #130
Replies: 7 comments 1 reply
-
It would be great to see what Option 3 would be like in practice for business logic authors. |
Beta Was this translation helpful? Give feedback.
-
I do think option 3 is compelling, and works for representation and storage, but does get problematic for interpretation and storage. That being said it becomes a runtime and implementation concern. |
Beta Was this translation helpful? Give feedback.
-
We do have a need to support the following operations though, thoughts on that? total: Int -> Int64 -> Int64
total quantity amount = Debug.todo("implement") |
Beta Was this translation helpful? Give feedback.
-
Thinking out - loud here, I wonder if maybe above could be represented by type refinements/phantom types. type alias Quantity min max = Int Of course we don't have singleton types (that I know of) so that might be out. The problem with the above is no way to express the following: type alias SmallQuantity = Quantity -100 100 |
Beta Was this translation helpful? Give feedback.
-
My above shower thought aside, how would we specify a function is meant to be at "the edge"? |
Beta Was this translation helpful? Give feedback.
-
By not having any operations on the Int64 type. So in order to use it, you'd have to convert it to Int. That solution is good for anti-corruption layer to keep logic pure. It doesn't help you optimize the backend performance. For that, is it acceptable to have a --performance flag that tells the backend to use long instead of arbitrary size int? |
Beta Was this translation helpful? Give feedback.
-
I believe so (and it sounds like we are pretty much on the same page here). I'm curious though, why a performance flag? Perhaps I'm failing to understand how we'll flow such a flag down. BTW, I can imagine how we could flow such a flag if the IR supported multiple attributes in its on disk representation as mentioned here: in #132 , but I feel we add un-needed ceremony to Morphir backends/runtimes requiring it to go through decorations. |
Beta Was this translation helpful? Give feedback.
-
On our last community meeting @DamianReeves brought up the topic of fixed-precision integer support in Morphir. Currently we do not specify a precision for our integers and we logically treat them as arbitrary precision. The main reason we do this is to avoid the complexity of dealing with what happens when the result of a computation doesn't fit into the specified precision. This is especially difficult in a language that doesn't allow runtime exceptions because we cannot statically decide if an operation will overflow at runtime or not. We have a few options to deal with this:
Result
.The first option yields APIs that are almost unusable due to the amount of boilerplate you would have to write. The second option is the one chosen by most mainstream programming languages but it trades correctness for efficiency. This makes sense for general purpose languages but for Morphir correctness is a priority.
To me, option 3 seems like the solution that would align most with Morphir's philosophy. This would mean that you could declare fixed precision integer types at the edges of the system but you would have to explicitly convert them to arbitrary precision for any calculations.
What does everyone think?
Beta Was this translation helpful? Give feedback.
All reactions