Skip to content

Instantly share code, notes, and snippets.

Kyle Headley kyleheadley

Block or report user

Report or block kyleheadley

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kyleheadley
kyleheadley / as_trait.rs
Last active Apr 1, 2018
Demonstration of casting to multiple trait objects
View as_trait.rs
use std::thread;
use std::sync::Arc;
use std::sync::RwLock;
struct Wrap{one:usize,zero:usize}
trait WriteIt {
fn write1(&mut self,w:usize);
fn read1(&self) -> usize;
}
@kyleheadley
kyleheadley / traitlang.rs
Created Nov 14, 2018
Example of typed functional programming in Rust's type-level language
View traitlang.rs
trait Nat {}
struct Zero;
impl Nat for Zero {}
struct Succ<N>(N);
impl<N:Nat> Nat for Succ<N> {}
type One = Succ <Zero >;
trait AddOne : Nat { type Result:Nat; }
impl<N:Nat> AddOne for N { type Result = Succ<N>; }
@kyleheadley
kyleheadley / trati-dsl.rs
Created Nov 14, 2018
A lambda DSL embedded in Rust
View trati-dsl.rs
#![allow(unused)]
// Meta values and functions
// -------------------------
// Bool values
struct False;
struct True;
// Option values
@kyleheadley
kyleheadley / untyped_lambda.rs
Created Aug 2, 2017
Implement the untyped lambda calculus in the Rust type system.
View untyped_lambda.rs
#![allow(unused)]
//#![feature(optin_builtin_traits)]
// Booleans
struct True;
struct False;
trait BoolOr<B> {type BoolOr;}
impl<B> BoolOr<B> for True {type BoolOr=True;}
impl BoolOr<True> for False {type BoolOr=True;}
impl BoolOr<False> for False {type BoolOr=False;}
@kyleheadley
kyleheadley / inherit.rs
Created Jan 4, 2018
A model for trait-based inheritance in Rust
View inherit.rs
//! Demo of static "inheritance"
//!
//! Use trait objects to get dynamic inheritance,
//! but casting to a subtype is not explored here
////////////////////////////////////////////////////////
// Define Base type, interface, and what is overloadable
////////////////////////////////////////////////////////
/// The main type that will be extended
@kyleheadley
kyleheadley / hkt_tree.rs
Last active Mar 18, 2020
demo a struct that can be used with Rc or Arc pointer types
View hkt_tree.rs
use std::ops::Deref;
use std::rc::Rc;
use std::sync::Arc;
trait PtrFunc<A> {type Ptr:Sized+Clone+Deref+From<A>;}
struct RcPtr;
impl<A> PtrFunc<A> for RcPtr {type Ptr = Rc<A>;}
struct ArcPtr;
impl<A> PtrFunc<A> for ArcPtr {type Ptr = Arc<A>;}
You can’t perform that action at this time.