Skip to content

Instantly share code, notes, and snippets.

@duane
duane / redw.lhs
Created December 27, 2011 11:10
Reddit aeson/bytestring
> {-# LANGUAGE OverloadedStrings #-}
This is the main driver of the program.
> module Main where
We need System.Environment for access command line arguments:
> import System.Environment (getArgs)
#[link_name = ""]
#[link_args = "BAD LINKING"]
native mod c {
fn random() -> int;
}
#[cfg(target_os = "macos")]
native mod c {
fn mach_absolute_time() -> u64;
}
#[cfg(target_os = "macos")]
#[link_name=""]
#[link_args = "-framework CoreServices"]
native mod CoreServices {
@duane
duane / gist:1475365
Created December 14, 2011 05:14
A merge-sort implementation
fn merge_sort<copy a>(&&d: [mutable a]) {
fn merge<copy a>(&&data: [mutable a], &&temp: [mutable a], low: uint, middle: uint, high: uint) {
let resultI = low;
let tempI = low;
let destI = middle;
while tempI < middle && destI <= high {
if data[destI] < temp[tempI] {
data[resultI] = data[destI];
resultI += 1u;
destI += 1u;
@duane
duane / gist:1474880
Created December 14, 2011 01:55
mutability not working?
use std;
fn poke(value: uint, index: uint, data: @mutable [mutable uint]) {
(*data)[index] = value;
}
fn main(_args: [str]) {
let vec = [mutable 4u];
std::io::println(#fmt["%u", vec[0]]);
poke(3u, 0u, @mutable vec);
@duane
duane / gist:1371111
Created November 16, 2011 19:43
Type error in small haskell program
module Main where
import Graphics.Sketch
import Data.Array.Repa
import Data.Word
import Control.Monad
import System.Random
randomWord8 :: IO Word8
@duane
duane / SmallVector.h
Created November 2, 2011 23:36
LLVM SmallVector
//===- llvm/ADT/SmallVector.h - 'Normally small' vectors --------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the SmallVector class.