Skip to content

Instantly share code, notes, and snippets.

@kyleheadley
kyleheadley / monad.rs
Last active Feb 8, 2017
Prototype implementation of Monads in Rust
View monad.rs
use std::fmt::Display;
trait Monadic {}
#[derive(Debug)]
struct Monad<M:Monadic,T>(M,T);
#[derive(Debug)]
struct Opt(bool);
impl Monadic for Opt {}
impl<T:Default> Monad<Opt,T> {
@kyleheadley
kyleheadley / sp17-proposal.md
Last active Mar 20, 2017
CSCI 7000 Spring '17 -- Course Project Proposal
View sp17-proposal.md

CSCI 7000 -- Course Project Proposal

Student name: Kyle Headley

Project Description:

  • Project kind: IC library implementation
  • Project details: Extend the rust implementation of the RAZ with additional incremental features.
View door_state.rs
#![allow(unused)]
use std::fmt::Debug;
#[derive(Debug)]
struct Door<S: DoorState> {
state: S,
}
trait DoorState {}
@kyleheadley
kyleheadley / impl-eq-types.rs
Created Jul 10, 2017
Possible alternative for missing type equality in rust trait impl's
View impl-eq-types.rs
trait F<V,X> {}
struct D;
trait TheV2 {
type IsThis;
}
impl<V1,V2> TheV2 for F<V1,V2> {
type IsThis = V2;
@kyleheadley
kyleheadley / type_fns.rs
Last active Jul 28, 2017
Show off type functions in rust with an example of 'type constructors'
View type_fns.rs
// emulates the type of a function from types 'E' to sequence-like types
pub trait SeqTypeFn<E> { type Result : SeqLike<E>; }
// sequence-like interface
pub trait SeqLike<E>{
fn new() -> Self;
fn push(self,e:E) -> Self;
fn first(&self) -> Option<&E>;
}
@kyleheadley
kyleheadley / listsearch.rs
Created Aug 1, 2017
Demonstrate searching a type-level list in rust
View listsearch.rs
#![allow(dead_code)]
struct True;
struct False;
impl IsEqual<False> for True {type Out=False;}
impl IsEqual<False> for False {type Out=True;}
impl IsEqual<True> for True {type Out=True;}
impl IsEqual<True> for False {type Out=False;}
trait Nat {fn inst()->usize;}
struct Zero;
@kyleheadley
kyleheadley / typeops.rs
Created Aug 1, 2017
Playing around with type-level operations in rust
View typeops.rs
#![allow(unused)]
#![feature(non_ascii_idents)]
// #![feature(conservative_impl_trait)]
// basic nats, my knowledge
mod nat {
pub trait Nat { fn to_usize() -> usize; }
pub struct Zero;
impl Nat for Zero { fn to_usize() -> usize { 0 } }
pub struct Succ<N>(pub N);
@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 / split_comma.rs
Last active Jan 2, 2018
Higher-order rust macro that assists in parsing by macro
View split_comma.rs
/// Higher-order macro fold function for pre-parsing comma separated lists
///
/// The commas on KEYWORD lines can be changed to parse lists with any
/// separator.
/// run a macro on a list of lists after splitting the input at commas
macro_rules! split_comma {
// no defaults
{$fun:ident <= $($item:tt)*} => {
split_comma![$fun () () () <= $($item)*]
@kyleheadley
kyleheadley / usez3.rs
Created Nov 11, 2017
Use pipes to communicate with z3 in rust
View usez3.rs
#![allow(unused)]
use std::error::Error;
use std::io::prelude::*;
use std::process::{Command, Stdio};
use std::str;
fn main() {
let process = match Command::new("z3")
// use any z3 language with another .arg() here
.arg("-in")
You can’t perform that action at this time.