Skip to content

Instantly share code, notes, and snippets.

@Sgeo
Created August 13, 2016 07:20
Show Gist options
  • Save Sgeo/cb93c06686da04a2ece4d0071c64f7f0 to your computer and use it in GitHub Desktop.
Save Sgeo/cb93c06686da04a2ece4d0071c64f7f0 to your computer and use it in GitHub Desktop.
#![feature(specialization)]
#![allow(dead_code)]
struct Nil;
struct Cons<H, T>(H, T);
struct Zero;
struct Succ<T>(T);
trait At<L> {
type Type;
fn at(&self) -> &Self::Type;
}
impl<Head, Tail> At<Zero> for Cons<Head, Tail> {
type Type = Head;
fn at(&self) -> &Head {
&self.0
}
}
impl<Head, Tail: At<Dec>, Dec> At<Succ<Dec>> for Cons<Head, Tail> {
type Type = Tail::Type;
fn at(&self) -> &Tail::Type {
&self.1.at()
}
}
trait ContainsWithin<T, Is> {}
impl<T, I, L: At<I, Type=T>, ITail> ContainsWithin<T, Cons<I, ITail>> for L {}
impl<T, I, L: At<I, Type=T>, IHead> ContainsWithin<T, Is> for L {}
fn main() {
}
@Sgeo
Copy link
Author

Sgeo commented Aug 13, 2016

Most promising approach so far. The great thing about indices is you can do type inequality on them, I just need to figure out how to put that into practice.

@Sgeo
Copy link
Author

Sgeo commented Aug 13, 2016

If ContainsWithin can be made to work, then Contains could just pass it a list of all valid indices. The compiler might melt down though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment