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

Syntax for the unit constraint? #5

Open
Centril opened this Issue Apr 6, 2018 · 6 comments

Comments

Projects
None yet
3 participants
@Centril
Copy link
Owner

Centril commented Apr 6, 2018

In the following example:

type FooBox<trait Extra = ()> = Box<dyn Foo + Extra>;

We have used () as the "unit trait", that is, a "trait" that adds no constraints.
This takes the approach in Haskell where we have the unit type (), the unit value () (of type ()), and the unit constraint ().

In Rust like Haskell, we do use () for the unit type and () for the unit value, but we understandably have no unit constraint.

Is this syntax legible in the sense that we understand that Extra = () means that
by default, and if nothing else is passed, the type alias becomes Box<dyn Foo>?

If not, what is a better syntax?

@comex

This comment has been minimized.

Copy link

comex commented Apr 6, 2018

@Centril

This comment has been minimized.

Copy link
Owner Author

Centril commented Apr 6, 2018

@comex

Oh wow; Tho that is on the RHS instead of LHS.
Then you'd write: type FooBox<trait Extra = > = Box<..>.
That becomes weirdly unbalanced :/

@kennytm

This comment has been minimized.

Copy link

kennytm commented Apr 6, 2018

Use Sized or ?Sized if you really need something not empty.

@Centril

This comment has been minimized.

Copy link
Owner Author

Centril commented Apr 6, 2018

@kennytm hmm... should it not be "if you need something empty" ?

@kennytm

This comment has been minimized.

Copy link

kennytm commented Apr 6, 2018

@Centril I mean if FooBox<trait Extra = > is unacceptable (i.e. you don't want an empty spot there), you may use Sized or ?Sized depending on the situation.

@Centril

This comment has been minimized.

Copy link
Owner Author

Centril commented Apr 6, 2018

@kennytm Right; Nicely spotted 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.