-
Notifications
You must be signed in to change notification settings - Fork 671
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
Proposal: type aliases in Clarity #1171
Comments
Custom types would be interesting. Also, perhaps we could have a generalized type test function like say |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Would be addressed if the |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Writing the same types in function parameters is long and tedious |
From the discussion: if implemented, these type definitions/aliases would be local to the current contract only. Edit: And an example where it would help: (define-type listing
{
maker: principal,
taker: (optional principal),
token-id: uint,
nft-asset-contract: principal,
expiry: uint,
price: uint,
payment-asset-contract: (optional principal)
}
)
(define-map listings {id: uint} listing)
(define-private (assert-can-fulfill (nft-asset-contract principal) (payment-asset-contract (optional principal)) (listing listing))
(begin
(asserts! (not (is-eq (get maker listing) tx-sender)) err-maker-taker-equal)
(asserts! (match (get taker listing) intended-taker (is-eq intended-taker tx-sender) true) err-unintended-taker)
(asserts! (< block-height (get expiry listing)) err-listing-expired)
(asserts! (is-eq (get nft-asset-contract listing) nft-asset-contract) err-nft-asset-mismatch)
(asserts! (is-eq (get payment-asset-contract listing) payment-asset-contract) err-payment-asset-mismatch)
(ok true)
)
) |
ClarityTools brings type aliases to Clarity, generating the polyfill. Check it out: Use |
Edit: I just saw the label changes by @jcnelson. I'll keep the post though. I'd like to bump this. Has any determination been made on whether or not to include such a feature? I think it could be a fantastic additional also for standardisation of types. Now that it seems that SIP018 is coming to Stacks we will see more custom tuple times be part of a larger protocol. Next to a (use-type type-alias type-identifier) Which would allow us to do something like this: (define-type order {maker: principal, amount: uint, salt: uint})
(use-type defi-order 'SP123.contract-a.order)
(define-public (some-func (order defi-order))
;; ...
) Thoughts? |
Assigning to @obycode for now. Please re-assign as appropriate. |
I like this idea too. I'm going to open an issue in the SIPs repo to track the proposal, then leave this one here for the implementation. |
In the context of the BNS contract, I'm dealing with the following type:
It could be nice, from a developer point of view, to have the ability to define type aliases, aiming at improving readability:
It could be an edge case not worthing the effort - opening an issue for tracking this idea.
The text was updated successfully, but these errors were encountered: