Skip to content

Instantly share code, notes, and snippets.

View stevenblenkinsop's full-sized avatar

Steven Blenkinsop stevenblenkinsop

View GitHub Profile

Response to the Go 2 Contracts Draft Design:
Auxiliary Types

Steven Blenkinsop
September 1, 2018

Summary

This response concerns generic types which are found in the signatures of methods on the inputs to a contract which are not themselves inputs to the contract, for example the type of elem in elem := stack.Pop(), where the type of stack is an input to the contract. It suggests formalizing these types as part of the signature of a contract, like

@stevenblenkinsop
stevenblenkinsop / playground.rs
Last active March 20, 2016 05:45 — forked from anonymous/playground.rs
Shared via Rust Playground
use std::any::Any;
trait Schema {
fn eq(&self, other: &Schema) -> bool;
fn as_any(&self) -> &Any;
}
impl PartialEq<Schema> for Schema {
fn eq(&self, other: &Schema) -> bool {
Schema::eq(self, other)
@stevenblenkinsop
stevenblenkinsop / playground.rs
Last active March 19, 2016 06:28 — forked from anonymous/playground.rs
Shared via Rust Playground
use std::any::Any;
trait Schema {
fn eq(&self, other: &Schema) -> bool;
fn as_any(&self) -> &Any;
}
impl<'a, 'b> PartialEq<Schema+'b> for Schema+'a {
fn eq(&self, other: &(Schema+'b)) -> bool {
Schema::eq(self, other)
@stevenblenkinsop
stevenblenkinsop / playground.rs
Created November 8, 2015 03:02 — forked from anonymous/playground.rs
Shared via Rust Playground
fn old() -> Vec<u8> {
let mut hash = vec![0u8; 8]; // vec of u8 representing the bits and bytes of the hash computed for the image.
let raw: Vec<_> = (0..8).flat_map(|_| (0 .. 9).rev()).collect(); // vec of u8 representing gray pixels of an 9x8 image.
for x in 0..8 {
for y in 0..8 {
if raw[x*9+y] > raw[x*9+y+1] {
hash[x] |= 0x1 << y
}
@stevenblenkinsop
stevenblenkinsop / playground.rs
Last active October 13, 2015 16:07 — forked from anonymous/playground.rs
Shared via Rust Playground
fn main() {
#![allow(unused)]
// A borrow can be moved out of the scope where it is created as long as the original value is
// known to live long enough. Here it is assigned to `out`. While `out` is in scope, `x` is
// inaccessible. When `out` goes out of scope, `x` becomes accessible again:
{
fn bar<'a>(x: &'a mut u32) -> &'a mut u32 { x }
let mut x = 1;
{
@stevenblenkinsop
stevenblenkinsop / playground.rs
Last active October 1, 2015 02:24 — forked from anonymous/playground.rs
Shared via Rust Playground
fn old() -> Vec<u8> {
let mut hash = vec![0u8; 8]; // vec of u8 representing the bits and bytes of the hash computed for the image.
let raw: Vec<_> = (0..8).flat_map(|_| (0 .. 9).rev()).collect(); // vec of u8 representing gray pixels of an 9x8 image.
for x in 0..8 {
for y in 0..8 {
if raw[x*9+y] > raw[x*9+y+1] {
hash[x] |= 0x1 << y
}
@stevenblenkinsop
stevenblenkinsop / playground.rs
Last active September 27, 2015 19:59 — forked from anonymous/playground.rs
Shared via Rust Playground
use std::marker::PhantomData;
struct Nothing;
#[allow(dead_code)]
struct Neg;
struct Zero<T: Num>(PhantomData<T>);
struct One<T: Num>(PhantomData<T>);
@stevenblenkinsop
stevenblenkinsop / playground.rs
Created August 25, 2015 03:59 — forked from anonymous/playground.rs
Shared via Rust Playground
trait T<'a> {
type A;
type Iter: Iterator<Item=Self::A>;
fn new() -> Self;
fn iter(&self) -> Self::Iter;
fn test() where Self: Sized {
let a = <Self as T<'a>>::new();
let _ = a.iter().map(|a| a);
fn function(_x: &i32) -> &i32 { &5th }
fn main() {
function();
}
@stevenblenkinsop
stevenblenkinsop / playground.rs
Created July 23, 2015 03:04 — forked from anonymous/playground.rs
Shared via Rust Playground
use std::ops::Deref;
fn main() {
let s: &'static str = "hello";
let x: &'static str = &*s;
let y: &'static str = s.deref(); // <-- lifetime error
}