Differentiate between Pair and 2-Tuples #564
Closed
MicroProofs
started this conversation in
Core language features
Replies: 3 comments 5 replies
-
More importance to this one now |
Beta Was this translation helpful? Give feedback.
0 replies
-
Updated the title post with more details. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First the what?
So in Aiken we represent all tuples of size 3 or greater as list of Data which is the same as how fields in a constructor are represented in uplc.
But 2 tuple makes use of one of the few primitives in uplc, Pair. Pair is quick to grab either item.
The why?
Using them in lists is friendly since that's a map structure. Using them in constructors though is not great. Lists hold them as pairs. But constructors can only hold data. So we must convert a pair to something that can represent the two items, which is a list.
A list can convert to data using listData builtin quickly and it can hold the pairs two items. But that conversion process to a list is not cheap. We must spend a bit of memory coding up a way to extract the two items from pair, add the two items to a list, and then call listData.
The Solution
In Aiken we can add a new primitive to the prelude called Pair<a, b>. This would be a type with a few special properties similar to how the BLS primitives also have a few special properties. The first would be Pair can be used by itself or in a List, but it can not be passed into a function that takes a generic argument or used inside any other type besides lists. To replace that 2 tuples and beyond which will now uniformly use arrays will work anywhere. The only place Pairs are commonly needed are the script context. In most cases users would end up using 2 tuples which would work the same as using 3+ tuples.
Beta Was this translation helpful? Give feedback.
All reactions