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

Iterating over finite spaces #29

Open
wschella opened this issue May 20, 2020 · 4 comments
Open

Iterating over finite spaces #29

wschella opened this issue May 20, 2020 · 4 comments

Comments

@wschella
Copy link

wschella commented May 20, 2020

Hi!

Recently I came to the conclusion that using the FiniteSpace trait in a generic way (when building other traits and abstractions) is quite unwieldy. I think boils down to the range() function being at the same time not powerful enough, and quite strict due to the return type of ::std::ops::Range.

  1. You can't implement Range<CustomType>, making it hard to implement Space for a custom type (i.e. an enum).
  2. Range<T> does not imply Range<T>: Iterator<Item = T>, requiring the need to specify this bound yourself, which is usually quite awkward. E.g.: Range<State<Self>>: Iterator<Item = State<Self>>. If this is in a trait, it also requires all implementors to copy this. Iterating comfortably over all values in a space seems like quite useful for a finite space.

So I would propose doing something like this:

pub trait FiniteSpace: Space {
    type Iter: Iterator<Item = Self::Value>;

    fn iter(&self) -> Self::Iter;
}

Would you be interested in receiving PR from me applying this change?

@wschella
Copy link
Author

Another option might be to do pub trait FiniteSpace: Space + IntoIterator<Item = <Self as Space>::Value>

@tspooner
Copy link
Owner

Hey, you make a good point about Range. Let me have a think about it and get back to you. On first thought I would rather avoid having an associated type like Iter as this adds considerable overhead. Ideally I want the traits to remain closer to the mathematics than the programming, if that makes sense.

Either way, FiniteSpace definitely needs to be revamped and perhaps this crate as a whole...

@tspooner
Copy link
Owner

Also, as always, sorry for the slow response. The NeurIPS deadline is coming up thick and fast, but rest assured I will get everything up once that's over.

@wschella
Copy link
Author

As always, no sweat, it's not urgent, I can work around it, and my use cases are not yours. Good luck with the experimenting / writing!

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

No branches or pull requests

2 participants