This file contains hidden or 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
#![allow(unused)] | |
// Meta values and functions | |
// ------------------------- | |
// Bool values | |
struct False; | |
struct True; | |
// Option values |
This file contains hidden or 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
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>; } |
This file contains hidden or 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
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>;} |
This file contains hidden or 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
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; | |
} |
This file contains hidden or 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
//! This file is a translation of the example code in the OCaml manual | |
//! chapter two,"The module system", into Rust code. | |
//! | |
//! The intent is to translate as directly as possible, to show OCaml | |
//! users a way to implement their functionality. This means that | |
//! later, more complex sections are neither idiomatic Rust nor a | |
//! perfect translation of the OCaml. Further study would be required, | |
//! but hopefully this helps explain some of the concepts. | |
//! | |
//! There are two constructs in Rust that might match OCaml modules, |
This file contains hidden or 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
//! 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 |
This file contains hidden or 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
#![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") |
This file contains hidden or 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
/// 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)*] |
This file contains hidden or 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
#![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;} |
This file contains hidden or 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
#![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); |
NewerOlder