Skip to content

Instantly share code, notes, and snippets.

@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.
@peterjoel
peterjoel / gist:3119341
Created July 16, 2012 00:13 — forked from kowey/gist:2420144
Haskell GTK on 64 bit MacOS X

Notes

  • on lion (and snow leopard i suppose), make sure you are using a 64 bit install of ghc. Also, unless you are suggesting an edit to these directions, please go ask people on the relevant mailing list or wiki for help :)
  • Tested on ghc 7.2.2, assumes you have standard developer things installed on mac, like x11 and stuff
  • Also tested on GHC 7.0.4 (Haskell Platform) with XCode 4.3.
  • These notes were originally brought to you by Carter Schonwald; the “I” probably refers to him. Eric Kow will refer to himself in the third person).

GHC 7.4.x

  • gtk2hs 0.12.2 won't build with ghc 7.4.1, but the current darcs repo for gtk2hs does build
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
-- {-# LANGUAGE FlexibleContexts #-}
module Main where
-- import Data.Bifunctor
class Functor f => Viewable f a b where
pub struct Fib {
value: u32,
next: u32,
}
impl Fib {
pub fn default() -> Fib {
Fib::new( 1, 1 )
}
pub fn new( a : u32, b : u32 ) -> Fib {
use std::ops::Add;
pub struct Fib<T>
where T : Add<Output = T> + Copy {
value: T,
next: T,
}
impl <T> Fib<T>
where T : Add<Output = T> + Copy {
In[1]:= GetCacheSizes[n_] := Module[{
CacheSizeBytesInit = 2^24,
CacheGrowth = 2^17,
HashBytes = 64,
j = 0},
Reap[
While[j < n,
Module[{i =
Floor[(CacheSizeBytesInit + CacheGrowth * j) / HashBytes]},
While[! PrimeQ[i], i--];
#[dom_struct]
pub struct DOMMatrixReadOnly {
reflector_: Reflector,
pub matrix: Cell<Matrix4>,
}
impl DOMMatrixReadOnlyMethods for DOMMatrixReadOnly {
fn M11(&self) -> f64 {
self.matrix.get().m11 as f64
}
.....
{
"path": "~/dev/rust/csswg-test/geometry-1/DOMMatrix-001.htm",
"url": "/DOMMatrix-003.htm"
},
....
peter$ cargo run
Compiling crypto_test v0.1.0 (file:///Users/peter/dev/rust/crypto_test)
error: linking with `cc` failed: exit code: 1
note: "cc" "-m64" "-L" "/Users/peter/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib" "/Users/peter/dev/rust/crypto_test/target/debug/crypto_test.0.o" "-o" "/Users/peter/dev/rust/crypto_test/target/debug/crypto_test" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/peter/dev/rust/crypto_test/target/debug" "-L" "/Users/peter/dev/rust/crypto_test/target/debug/deps" "-L" "/Users/peter/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib" "/Users/peter/dev/rust/crypto_test/target/debug/deps/libsecrets-0014f6abd3757ae1.rlib" "/Users/peter/dev/rust/crypto_test/target/debug/deps/liblibc-dd3420cb049117bb.rlib" "/Users/peter/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/libstd-fd663c41.rlib" "/Users/peter/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/libcollections-fd663c41.rlib" "/Users/peter/.multirust/toolchain
@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;
}