Skip to content

Instantly share code, notes, and snippets.

@peterjoel
peterjoel / Update.rs
Last active December 31, 2016 14:24
When using RefCells and mutable borrows, you have to take care not to accidentally borrow the same value twice. The Update trait allows you to contain borrows in a natural method scope or closure.
use std::cell::RefCell;
trait UpdateMut<T:?Sized> {
fn update_mut <F> (&self, f: F) where F: Fn(&mut T);
}
trait Update<T> {
fn update <F> (&self, f: F) where F: Fn(&T) -> T;
}
@peterjoel
peterjoel / Uninstall.hs
Created December 18, 2011 02:14 — forked from mzero/UninstallHS.hs
Mac OS X Haskell Uninstaller preview
#!/usr/bin/env runghc
module Main where
{-
Uninstall.hs - a Haskell uninstaller for Mac OS X
This program is really far too big to be in a single file. However, I
wanted it to be easily distributable and runnable, and so have kept it all
together.