Probably it wouldnât make sense for collection (if, indeed, anything would). I think it came to mind mostly because of the direct mapping to HKT.
I think there are a few things where a âfamily-likeâ trait might make sense. One thing might be to group together a bunch of related types.
Another is if you want to let people customize how you work internally, but you donât expose those types at the interface. i.e., instead of taking or returning a collection, you are just using it internally, and you want people to be able to choose whether you use a Vec or a List (for some reasonâŚ)
Or maybe something like:
trait SharedBoxFamily {
type Member<T>: Clone + Deref<Target=T>;
}
struct RcFamily;
impl SharedBoxFamily for RcFamily {
type Member<T> = Rc<T>;
}
struct ArcFamily;
impl SharedBoxFamily for ArcFamily {
type Shared<T> = Arc<T>;
}
Then I can have a tree that is parameterized over a SharedBoxFamily:
struct MyTree<F: SharedBoxFamily> {
node: F::Member<MyTreeData<F>>
}
struct MyTreeData<F: SharedBoxFamily> {
data: usize,
left: Option<MyTree<F>>,
right: Option<MyTree<F>>,
}
type RcTree = MyTree<RcFamily>;
type ArcTree = MyTree<ArcFamily>;
If you didnât have a family trait here, those type aliases would be:
type RcTree = MyTree<Rc<()>>;
type ArcTree = MyTree<Arc<()>>;
where the () in Rc<()> is just a âdummy typeâ that we donât really use.