-
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
[Docs] [Builtins] Add Note [How to add a built-in function: simple cases] #4338
Merged
effectfully
merged 2 commits into
master
from
effectfully/builtins/add-note-how-to-add-a-simple-builtin-function
Jan 23, 2022
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev
Previous commit
Apply suggestions from code review
Co-authored-by: Kenneth MacKenzie <kwxm@inf.ed.ac.uk>
- Loading branch information
commit f6bc22af475edc2b4451d8fcd5ff00403f653c7e
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,7 +137,7 @@ in relevant files (will have a proper overview doc on that, but for now you can | |
comment: https://github.com/input-output-hk/plutus/issues/4306#issuecomment-1003308938). | ||
|
||
In order to add a new built-in function one needs to add a constructor to 'DefaultFun' and handle | ||
it within the @ToBuiltinMeaning uni DefaultFun@ instance like that: | ||
it within the @ToBuiltinMeaning uni DefaultFun@ instance like this: | ||
|
||
toBuiltinMeaning <Name> = | ||
makeBuiltinMeaning | ||
|
@@ -168,7 +168,7 @@ builtin (out of the scope of this Note) and handling it within the @Flat Default | |
(see Note [Stable encoding of PLC]). | ||
|
||
2. If the type of the denotation has any constrained type variables in it, all of them need to be | ||
be instantiated. For example feeding @(+)@ directly to 'makeBuiltinMeaning' will give you an error | ||
instantiated. For example feeding @(+)@ directly to 'makeBuiltinMeaning' will give you an error | ||
message asking to instantiate constrained type variables, which you can do via an explicit type | ||
annotation or type application or using any other way of specifying types. | ||
|
||
|
@@ -289,7 +289,7 @@ the denotation is monomorphic or polymorphic w.r.t. failing. | |
|
||
But note that | ||
|
||
'EvaluationResult' MUST BE EXPLICIYLY USED FOR ANY FAILING BUILTIN AND THROWING AN EXCEPTION | ||
'EvaluationResult' MUST BE EXPLICITLY USED FOR ANY FAILING BUILTIN AND THROWING AN EXCEPTION | ||
VIA 'error' OR 'throw' OR ELSE IS NOT ALLOWED AND CAN BE A HUGE VULNERABILITY. MAKE SURE THAT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OR ELSE? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
NONE OF THE FUNCTIONS THAT YOU USE TO DEFINE A BUILTIN THROW EXCEPTIONS | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Perhaps emphasise that this is the Haskell type of the denotation and that's where the type variables are coming from (I know the denotation's a Haskell object, but it's easy to get confused when there are two different type systems in play).
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.
I spent several minutes trying to come up with a way to make that clarification, but it just all looks worse. So I could say "If the Haskell type of the denotation has any constrained type variables in it", but that sounds like a denotation can have a non-Haskell type, which it can't. A builtin can have a Plutus type and a Haskell type, but a denotation is always a Haskell object. Plus, it's really unambiguous here which language is meant, because Plutus Core does not have any constraints. I agree it's easy to get confused in general, but I think in this particular case things are pretty unambiguous, given that the "denotation" term is introduced have a screen above and it's explicitly stated that a denotation is a Haskell implementation.
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.
But if you think there's a better way of formulating that part, do write it down, I'll include it in a subsequent PR, or feel free to adjust the docs yourself.