-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
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).
// The kind * -> *
trait TypeToType<Input> {
type Output;
}
struct Vec_;
impl<T> TypeToType<T> for Vec_ {
type Output = Vec<T>;
}
trait Mappable
where Self: Sized,
{
type E;
type HKT: TypeToType<Self::E, Output=Self>;
fn map<F, O>(self, f: F) -> <Self::HKT as TypeToType<O>>::Output
where F: FnMut(Self::E) -> O,
Self::HKT: TypeToType<O>;
}
impl<T> Mappable for Vec<T> {
type E = T;
type HKT = Vec_;
// FIXME: I won't unify `Vec_::Output = Vec<O>`!
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();
r
}
}
fn main() {
let nums: Vec<u32> = vec![1, 2, 3, 4, 5, 6];
let bools: Vec<bool> = nums.map(|x| x < 3);
}
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-type-systemArea: Type systemArea: Type systemC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.