-
Notifications
You must be signed in to change notification settings - Fork 30
Add AsData x
type constructor and functions to work with it
#185
Comments
If these functions need to work on-chain, |
I really like this idea, would love to see it happen |
How are end users expected to do arbitrary manipulation on |
@re-xyr That is an option, but I was serious about the function name: it really would be inefficient to convert |
If i understood correctly, the family of functions that extracts |
Yes, that's correct. It's very easy to write a function that type-checks, yet extracts a wrong field or something that's not even a field. That's why it would be best to generate all the field accessor functions automatically. Ideally they would be lenses and not just getters, but I fear that would be too much for Plutus to handle. |
@blamario i've experimented a little. Questions so far:
|
Good questions all.
User-defined sum types will be tricky to support safely and efficiently at the same time, and I'd suggest leaving them off for now. As far as Haskell goes, it could be done using generics and constructor labels, or alternatively requiring higher-kinded data declarations. The problem is, I don't know if
For data types built into Plutus, we'd provide all field accessors by name and hide the ugliness.
Again, if you're asking about user-defined types this would depend on how much
Is the only problem that it's missing the |
On the second thought, we can definitely implement safe answers for your first two questions using Template Haskell. So if the user had
the splice could expand to
with the obvious definitions. |
Also, assuming
|
No there's no urgency. |
The secret of Plutarch's efficiency comes down to two simple rules:
Data
decoding as long as possible.There's not much PlutusTx users can do about the former, though Shrinker can help. The second technique, on the other hand, can be translated to PlutusTx thus:
AsData
type constructor to correspond with Plutarch'sPAsData
, along withAsData ScriptContext
to its fields, and same for all the product types it contains. For exampleWe should be able to generate all of these functions using either
Generics.SOP
or Template Haskell.ScriptContext
, such asThe text was updated successfully, but these errors were encountered: