Skip to content

Instantly share code, notes, and snippets.

View aturon's full-sized avatar

Aaron Turon aturon

View GitHub Profile
@aturon
aturon / gist:2630073
Created May 7, 2012 20:08
early reagent code generation
(define-reagent (push s x)
(read-match s
[xs (update-to! (cons x xs))]))
; --generates->
(define (push s x)
(let retry40 ()
(let ([b41 (atomic-ref-box s)]
[ov42 (unsafe-unbox* b41)])
@aturon
aturon / escape.rkt
Created May 4, 2012 20:12
racket's escape analysis
; when compiled, does this code ...
(define (abs x)
(define (f)
(if (> x 0) x (g))
(define (g)
(- 0 x))
(f))
; ... turn into this code?
@aturon
aturon / aca-unique.txt
Created April 29, 2012 16:07
unique words in ACA
abbreviated
abnormality
abrogate
absent
absolute
abusive
academically
accommodate
accompany
accompanying
@aturon
aturon / gist:1207265
Created September 9, 2011 20:34
The Burke-Fisher functor
signature PARSER =
sig
type token
val exampleToks: token list
type span = (int * int)
type 'stream lexer = 'stream -> token * span * 'stream
type result
exception ParseError of span
val parse: 'stream lexer -> 'stream -> result
implicit def str2toInt(s: String): { def toInt: Int } = new {
def toInt: Int = java.lang.Integer.parseInt(s)
}
trait AsRef<T: ?Sized> {
fn convert_as_ref(&self) -> &T;
}
trait Into<T> {
fn convert_into(self) -> T;
}
trait From<T> {
fn from(T) -> Self;
// As lifts over Deref
impl<D: ?Sized + Deref, U: ?Sized> AsRef<U> for D where D::Target: AsRef<U> {
fn as_ref(&self) -> &U {
self.deref().as_ref()
}
}
trait Rand<Distribution> {
type Stream: RandStream<T>;
fn rand(dist: Distribution) -> Stream;
}
trait RandStream<T> {
fn next<R: Rng>(&self, rng: &mut R) -> T;
}
impl Rand<Range<u32, u32>> for u32 {
trait Rand<Rng, Distribution> {
type Iter: Iterator<Item = Self>;
fn rand(rng: Rng, dist: Distribution) -> Iter;
}
fn nonparametric<T: 'static>(t: T) {
let b: Box<Any> = box t;
match b.downcast::<SomeConcreteType>() {
...
}
}