Created
August 13, 2016 07:20
-
-
Save Sgeo/cb93c06686da04a2ece4d0071c64f7f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![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() { | |
} |
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
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.