Skip to content

Instantly share code, notes, and snippets.

@dylanede
dylanede / hkt.rs
Last active August 29, 2015 14:24 — forked from anonymous/playground.rs
trait Apply {
type Out;
}
trait Unapply {
type Out;
}
type Applied<F, T> = <(F, T) as Apply>::Out;
type Unapplied<T> = <T as Unapply>::Out;
//This trait is not used, but is useful for type equality constraints
trait ID {
type Out;
}
impl<T> ID for T {
type Out = T;
}
trait CanApply {
type Out: CanUnapply;
//This trait is not used, but is useful for type equality constraints
trait ID {
type Out;
}
impl<T> ID for T {
type Out = T;
}
trait CanApply {
type Out: CanUnapply;
@dylanede
dylanede / playground.rs
Created October 16, 2015 13:00 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(optin_builtin_traits)]
use std::marker::PhantomData;
struct Nil;
struct Cons<H, T>(H, T);
struct Zero;
struct One;
trait UInt {
@dylanede
dylanede / playground.rs
Created October 17, 2015 13:45 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(optin_builtin_traits)]
use std::marker::PhantomData;
struct Nil;
struct Cons<H, T>(H, T);
struct Pair<A, B>(A, B);
trait Lookup_<S, Env> { type Type; }
type Lookup<S, Env> = <() as Lookup_<S, Env>>::Type;
@dylanede
dylanede / playground.rs
Created October 17, 2015 16:54 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(optin_builtin_traits)]
use std::marker::PhantomData;
struct Nil;
struct Cons<H, T>(H, T);
struct Pair<A, B>(A, B);
trait Lookup_<S, Env> { type Type; }
type Lookup<S, Env> = <() as Lookup_<S, Env>>::Type;
@dylanede
dylanede / playground.rs
Created October 18, 2015 21:08 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(optin_builtin_traits)]
use std::marker::PhantomData;
trait Lookup<K> {
type V;
fn get(&self) -> &Self::V;
}
struct Nil;
@dylanede
dylanede / playground.rs
Created October 18, 2015 21:20 — forked from anonymous/playground.rs
Shared via Rust Playground
#![feature(optin_builtin_traits)]
use std::marker::PhantomData;
trait Lookup<K> {
type V;
fn get(&self) -> &Self::V;
}
struct Nil;
@dylanede
dylanede / playground.rs
Created January 5, 2016 21:50 — forked from anonymous/playground.rs
Shared via Rust Playground
use std::collections::HashMap;
use std::marker::PhantomData;
use std::collections::hash_map;
pub trait DiffableIters<'a, T: Diffable> where T::Key: 'a, T::ListChild: 'a {
type KeyIter: Iterator<Item=&'a T::Key>;
type ListChildIter: Iterator<Item=&'a T::ListChild>;
}
pub type KeyIter<'a, T> = <T as DiffableIters<'a, T>>::KeyIter;
@dylanede
dylanede / widget.rs
Created January 7, 2016 23:22 — forked from anonymous/playground.rs
Shared via Rust Playground
use std::any::Any;
use std::rc::Rc;
trait AsAny {
fn as_any(&self) -> &Any;
}
impl<T: Any> AsAny for T {
fn as_any(&self) -> &Any { self }
}