Skip to content

Instantly share code, notes, and snippets.

@msullivan
msullivan / gist:2996840
Created June 26, 2012 16:25
traits thing
#[warn(no_vecs_not_implicitly_copyable)];
iface to_str {
fn to_str() -> str;
}
impl of to_str for int {
fn to_str() -> str { int::to_str(self, 10u) }
}
impl of to_str for str {
@msullivan
msullivan / gist:2996876
Created June 26, 2012 16:27
traits thing that doesn't work
import dvec::dvec;
iface core_iter<A> {
fn each2(blk: fn(A) -> bool);
}
impl core_iter<A> for option<A> {
fn each2(f: fn(A) -> bool) {
alt self {
@msullivan
msullivan / snapshot helper
Created June 29, 2012 22:30
helper script for making snapshots
#!/bin/bash
# Hacky script to assist in updating the snapshot files.
# Give it the log urls as arguments for the snap-stage3 builds and it
# will produce something to paste into snapshots.txt.
STRINGS=$(for URL in "$@"
do
FNAME=${URL/html/txt}
wget -q -O- "$FNAME" | sed 's/\\n/\n/g'| grep 'Public URL' | cut -d- -f5- | cut -d. -f1
done)
iface builder<A> {
// This would have some methods
}
impl extensions<A: copy> of builder<A> for @[A] { }
// Pretend that these are static typeclass methods
fn new_container<A,IA:builder<A>>() -> IA {
fail "this is a dummy for type inference testing!"
}
@msullivan
msullivan / gist:3035496
Created July 2, 2012 20:27
frumious hack for static typeclass methods
iface builder<A> {
// These "static" methods ignore their self parameter
fn __new_container() -> self;
fn __push(&_v: self, +_x: A);
}
impl extensions<A: copy> of builder<A> for ~[A] {
fn __new_container() -> ~[A] { ~[] }
fn __push(&v: ~[A], +x: A) { vec::push(v, x); }
}
@msullivan
msullivan / static-trait-methods.rs
Created July 13, 2012 00:09
thoughts about vec construction and static fns
/*
Currently, all trait methods must take an implicit self parameter,
which is limiting in a lot of cases.
I propose that we add a notion of "static" trait methods (although I
don't really like that name). These are simply trait functions that do
not take a self parameter. These functions would be called like
regular functions, and the names would live in the module where the
trait is declared.
mod foo {
fn f() { }
}
mod bar {
import foo::f;
mod foo {
fn thing() { f(); }
}
import task::{local_data_get, local_data_set};
fn display_callback_tls_key(+_callback: @fn@()) {
// Empty.
}
fn display_callback() unsafe {
let callback = local_data_get(display_callback_tls_key).get();
(*callback)();
}
@msullivan
msullivan / snapshot_helper.sh
Created July 31, 2012 17:19
script to help make snapshot info
#!/bin/bash
# Hacky script to assist in updating the snapshot files.
# Give it the log urls as arguments for the snap-stage3 builds and it
# will produce something to paste into snapshots.txt.
STRINGS=$(for URL in "$@"
do
FNAME=${URL/html/txt}
wget -q -O- "$FNAME" | sed 's/\\n/\n/g'| grep 'Public URL' | cut -d- -f5- | cut -d. -f1
done)
{-# LANGUAGE GeneralizedNewtypeDeriving, GADTs #-}
data SameType a b where
Refl :: SameType a a
coerce :: SameType a b -> a -> b
coerce Refl = id
trans :: SameType a b -> SameType b c -> SameType a c
trans Refl Refl = Refl