-
Notifications
You must be signed in to change notification settings - Fork 483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add docs on data-backed ScriptContext #6759
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation should follow the format of having one sentence per line.
As an initial thought, here are some things that should be mentioned - I may have more to add later.
- When extracting fields from ScriptContext (and in general all Data-encoded types), don't use field accessors, but use record patterns to extract all needed fields at the beginning (and briefly explain why).
- If your data type includes fields that are lists or maps and you want to wrap it in
asData
, make sure to use the Data versions of map and list.
@zliu41 I'm not sure I understand why. As far as I could see, the record patterns are just syntactic sugar over the field accessor functions. I need to look at the way GHC transforms record patterns into Haskell Core again, but I never got the impression the record pattern syntax makes any difference at that level. I assume you're not referring to the behavior you discovered with matching on pattern synonyms like |
Using field accessors leads to repetitive computation. Extracting the third field is |
By the way see this slack thread: https://input-output-rnd.slack.com/archives/G01EE4NQ9U0/p1728897590920289 |
Also have a look at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Fixes https://github.com/IntersectMBO/plutus-private/issues/1213