Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis
nikomatsakis / .gitignore
Created November 4, 2011 15:42
Regional Rust
*~
@nikomatsakis
nikomatsakis / categories.md
Created November 8, 2011 17:47
"Categories", "object extensions", or just "objects without classes"

Categories

Goals

This proposal is a bridge Haskell's type classes and class-based OOP. It also addresses a pet theme of mine, which is the ability to add methods to classes and define groups of related methods together.

The core unit of organization is called a category, and it is a bundle of statically dispatched methods based on a shared receiver type (a

@nikomatsakis
nikomatsakis / no-copies.md
Created November 30, 2011 21:08
Eliminating implicit copies

The primary goal of this proposal is to eliminate implicit copies of aggregate types, while preserving most other aspects of the language. Secondary goals include: permit references into arrays; make DPS a guaranteed optimization that is obvious from language syntax.

Summary

The following changes are made:

  • vectors become fixed-length arrays;
@nikomatsakis
nikomatsakis / hashtable-prob.md
Created December 2, 2011 04:22
Addressing "the hashtable problem" with modular type classes

The "Hashtable Problem"

There is a danger with typeclasses only on functions because they permit a lack of coherence. This danger is particularly acute with collections, where the definition of a particular interface---such as hashable or ord---may be used in structuring the data structure. This renders the data structure corrupt when used with a different implementation.

To see the problem, consider a hashtable defined something like this:

@nikomatsakis
nikomatsakis / trace-allocs.dtrace
Created December 14, 2011 22:43
d-trace script to profile allocations
#!/usr/sbin/dtrace -s
pid$target::upcall_malloc:entry
{
@task[ustack(10)] = count()
}
pid$target::upcall_shared_malloc:entry
{
@task[ustack(10)] = count()
fn foo() -> {x: int, y: int} {
let x_coord = ...;
let y_coord = ...;
ret {y: y_coord, x: x_coord};
}
@nikomatsakis
nikomatsakis / gist:1679581
Created January 25, 2012 23:14
etags-select
;;; etags-select.el --- Select from multiple tags
;;; From http://www.emacswiki.org/emacs/download/etags-select.el
;; Copyright (C) 2007 Scott Frazer
;; Author: Scott Frazer <frazer.scott@gmail.com>
;; Maintainer: Scott Frazer <frazer.scott@gmail.com>
;; Created: 07 Jun 2007
;; Version: 1.13
;; Keywords: etags tags tag select
enum deser = uint;
iface reader {
fn read_vec_elt<T:copy>(f: fn() -> T) -> T;
}
impl of reader for deser {
fn read_vec_elt<T:copy>(f: fn() -> T) -> T {
f()
}
@nikomatsakis
nikomatsakis / gist:1947382
Created March 1, 2012 04:55
simple one-writer revisions in C++
namespace revisions {
using namespace std;
class graph_t;
class version_t {
private:
graph_t *graph;
unsigned id;

Running this program:

use std;
import std::io;

fn iter(&&v: [uint], f: fn(uint)) {
    for i in v { f(i) }
}