Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upCan't Unify Super Generic Code #31580
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@jonas-schievink Yes, I think you're right -- the projection works if you define a helper like: fn project<O>(v: Vec<O>) -> <Vec_ as TypeToType<O>>::Output {
v
} |
aturon
closed this
Feb 11, 2016
This comment has been minimized.
This comment has been minimized.
|
Actually, I was a bit too hasty: HRTBs are not clearly at fault here, since there's no lifetime involved in the |
aturon
reopened this
Feb 11, 2016
This comment has been minimized.
This comment has been minimized.
|
The full fix, to be clear: fn project_vec<O>(v: Vec<O>) -> <Vec_ as TypeToType<O>>::Output {
v
}
impl<T> Mappable for Vec<T> {
type E = T;
type HKT = Vec_;
fn map<F, O>(self, mut f: F) -> <Self::HKT as TypeToType<O>>::Output
where F: FnMut(Self::E) -> O,
Self::HKT: TypeToType<O>
{
let r: Vec<O> = self.into_iter().map(&mut f).collect();
project_vec::<O>(r)
}
}But this shouldn't be necessary. |
steveklabnik
added
the
A-typesystem
label
Feb 15, 2016
soltanmm
referenced this issue
Apr 30, 2016
Merged
Generic associated types (associated type constructors) #1598
Mark-Simulacrum
added
the
C-bug
label
Jul 24, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gankro commentedFeb 11, 2016
I was trying to verify that the associated-items-based HKT described in the associated items RFC still worked. As best I know, I updated everything to work with today's stable Rust (1.7), but it fails out in unifying in the actual implementation of
Mappable for Vec<T>(see the FIXME).