-
Notifications
You must be signed in to change notification settings - Fork 139
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 HashableStruct type #2428
Comments
@turbolent is this issue is resolved ? if yes humble request please can we mark it as closed ? |
No, this feature has not been added yet, contributions are very welcome |
@turbolent please assign this to me. I will start looking into it. |
@turbolent thank you I can see in pratt parser core logic where operator precedence get checked is used for parsing is there any developer documentation available please share it with me ? |
@PratikDhanave Sorry, I'm not quite understanding what you are asking for. Are you asking for general developer documentation, or specifically for the operator precedence logic in the parser? BTW, for this issue, there is no work in the parser necessary, just in the type checker and interpreter. |
hi @turbolent thank you for info I am working on it |
hi @turbolent is this correct ? // HashableStruct var TheHashableStructType = HashableStruct{} func NewTheHashableStruct() HashableStruct { func (HashableStruct) isType() {} func (HashableStruct) ID() string { func (t HashableStruct) Equal(other Type) bool { |
@PratikDhanave That should be it for the Note that the former does not introduce a Cadence subtyping relationship as you might think, that needs to be implemented in the |
@turbolent thank you for your feedback I will work on it and raise PR. |
I'll pick this up unless @PratikDhanave is actively working on it. |
@turbolent What should be the interface definition? I have the following in mind. pub struct interface HashableStruct {
pub fun hash(): [UInt8]
} Since the sema generator doesn't support interface, I'll model it in Go. |
Eventually, a type similar to this would be nice to have, as it would allow developers to make their types hashable / usable as dictionary keys. As a start, it would be nice to just have a type Later, this type could become an interface, and thus implementable by developers for their types. However, that requires some more work. Unlike in other languages, which require an implementation of a function like (@fxamacker can you remind me why we want the type prefix/indicator? Unfortunately, I don't seem to have documented it and don't remember either) |
Having a type prefix/indicator in hash input is to reduce hash collisions. Different types can have same hash input value if we don't include the type prefix. For example, If users are allowed to provide entire hash input, would that make it easier for users to intentionally or accidentally cause numerous hash collisions? |
@fxamacker I see, thanks for the reminder, great explanation! I guess if we let user types to become hashable, we neither want to burden developers with having to manually include type information to avoid collisions, nor want to let user code intentionally omit them so they can cause many collisions. |
Issue to be solved
Currently there is no type exposed to Cadence programs which represents the type that can be used as a
Dictionary
key type.Suggested Solution
Tasks
The text was updated successfully, but these errors were encountered: