Skip to content
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

[book] Witness #67

Merged
merged 3 commits into from
May 24, 2024
Merged

[book] Witness #67

merged 3 commits into from
May 24, 2024

Conversation

damirka
Copy link
Collaborator

@damirka damirka commented May 21, 2024

No description provided.

@damirka damirka requested a review from amnn May 21, 2024 14:39
@damirka damirka self-assigned this May 21, 2024
@damirka damirka requested review from tnowacki and tzakian May 21, 2024 15:19
Copy link
Contributor

@amnn amnn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it!

Comment on lines +3 to +5
Witness is a pattern of proving an existence by constructing a proof. In the context of programming,
witness is a way to prove a certain property of a system by providing a value that can only be
constructed if the property holds.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if you need the first sentence -- I think it might be fine to drop it. It overlaps with the next sentence, and I'm having a hard time getting it to work just right because "an existence" makes me wonder "of what", and it's kind of the other way around, "the existence of the witness is the proof of some property, by construction", but this is essentially what you are saying in the next line.

Suggested change
Witness is a pattern of proving an existence by constructing a proof. In the context of programming,
witness is a way to prove a certain property of a system by providing a value that can only be
constructed if the property holds.
In the context of programming, a witness is a way to prove a certain property of a system by providing a
value that can only be constructed if the property holds.

```
Practically speaking, for the witness to be used, there has to be a function that expects a witness
as an argument. In the example below it is the `new` function that expects a witness of the `T` type
to create a `Instance<T>` instance.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit

Suggested change
to create a `Instance<T>` instance.
to create an `Instance<T>` instance.

}
}
```

## "Abstract Class"
The instance of the struct `W` is passed into the `new` function to create an `Instance<W>`, thereby
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth reinforcing here that if you are given an Instance<W> you know that it came from the module that defined W as long as there isn't a public function in that module that constructs values of type W?

The following example demonstrates a custom `RegulatedCoin` type with implementable functions. The
actual implementation of the `mint`, `burn`, and `transfer` functions is left to the application
module, while the `join` function is publicly available.
Witness allows generic types to be instantiated with a concrete type. This is useful for inheriting
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section seems to be trying really hard to avoid terms like "abstract class" or "inheritance" -- is that intentional? Here's the best I could come up with without that restriction:

Witnesses can be used to create a pattern resembling abstract classes, where one module implements base functionality for another module to delegate to or override.

available and does not require a Witness.
In the example above, which is borrowed from the `balance` module of the
[Sui Framework](./sui-framework.md), the `Supply` a generic struct that can be constructed only by
supplying a witness of the type `T`. The witness is taken by value and _discarded_ - hence the `T`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
supplying a witness of the type `T`. The witness is taken by value and _discarded_ - hence the `T`
supplying a witness of the type `T`. The witness is taken by value and _discarded_ - hence `T`

> consume a Ticket) for the sake of clarity and simplicity. The full example is available in the
> [Move Book](https://github.com/MystenLabs/move-book/tree/main/packages/samples/examples)
> repository.
The instantiated `Supply<T>` can then be used to mint new `Balance<T>`'s, where `T` is the type of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential reinforcing point here: It allows the module that defines T (the coin marker type) to control when and how supply is created and destroyed.

@damirka damirka merged commit d28a6a5 into main May 24, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants