Skip to content

Instantly share code, notes, and snippets.

View acfoltzer's full-sized avatar

Adam C. Foltzer acfoltzer

View GitHub Profile
@acfoltzer
acfoltzer / gist:1052530
Created June 28, 2011 23:50
PG variables
(*
*** Local Variables: ***
*** coq-prog-name: "coqtop" ***
*** coq-prog-args: ("-emacs-U" "-I" "sf") ***
*** End: ***
*)
@acfoltzer
acfoltzer / gist:1242902
Created September 26, 2011 18:09
Prototype heterogenous unifier
{-# LANGUAGE GADTs #-}
import Control.Applicative
import Data.Dynamic
import Data.Maybe
type Id = Integer
data Val where
Var :: Id -> Val
@acfoltzer
acfoltzer / gist:1321567
Created October 28, 2011 03:38
No stacks to overflow here...
import java.util.Formatter;
public class _interp {
//labels
static final int _value$_of = 0;
static final int _apply$_k = 1;
static final int _apply$_env = 2;
static final int _apply$_proc = 3;
//registers
@acfoltzer
acfoltzer / tagless.hs
Created November 27, 2011 23:01
Tagless final games
-- No LANGUAGE pragmas! This is all barebones Haskell.
-- $ ghc --make -O2 -fllvm -fforce-recomp tagless.hs
import Control.Applicative
import Control.Monad.Reader hiding (fix)
import Control.Monad.State hiding (fix)
import Criterion.Main
-- An example of how multiple backends can be achieved for an EDSL
@acfoltzer
acfoltzer / cas.hs
Created December 8, 2011 16:37
Pointer equality woes
import Data.CAS
import Data.IORef
test1 = do ref <- newIORef 0
let old = 0
new = (old+1)
casIORef ref old new
test2 = do let old = 0
ref <- newIORef old
@acfoltzer
acfoltzer / FixFact.hs
Created January 12, 2012 01:15
Fix at work
fix :: (a -> a) -> a
fix f = f (fix f)
fact' :: (Integer -> Integer) -> Integer -> Integer
fact' = \bang -> \n -> if n == 0 then 1 else n * bang (n-1)
fact :: Integer -> Integer
fact = fix fact'
onehundredandtwenty :: Integer
@acfoltzer
acfoltzer / amb.scm
Created February 21, 2012 22:20
amb with ivars
;; Adam Foltzer
;; amb with ivars
(load "pmatch.scm")
;;;; Global scheduler queue and helpers; ugly!
(define *q* '())
(define push-right!
(lambda (x)
@acfoltzer
acfoltzer / Vector.hs
Created March 1, 2012 05:10
Prototype Accelerate Vector conversions
{-# LANGUAGE CPP, TypeFamilies #-}
{-# OPTIONS_GHC -Wall #-}
-- | Helpers for fast conversion of 'Data.Vector.Storable' vectors
-- into Accelerate arrays.
module Data.Array.Accelerate.IO.Vector where
import Data.Array.Accelerate ( arrayShape
, Array
, DIM1
@acfoltzer
acfoltzer / radix_acc.hs
Created March 5, 2012 14:40
Radix sort kaboom
afoltzer@beetle ~/src/monad-par/examples [meta*]$ ghc-pkg list | grep accelerate
accelerate-0.9.0.1
afoltzer@beetle ~/src/monad-par/examples [meta*]$ ghc --make -O2 radix_acc.hs
[1 of 1] Compiling Main ( radix_acc.hs, radix_acc.o )
radix_acc.hs:19:1:
Warning: In the use of `M.unsafeFreeze'
(imported from Data.Array.MArray):
Deprecated: "Please import from Data.Array.Unsafe instead; This will be removed in the next release"
Linking radix_acc ...
@acfoltzer
acfoltzer / Affinity.hs
Created March 9, 2012 05:42
Haskell affinity
{-# LANGUAGE ForeignFunctionInterface #-}
module System.Posix.Affinity (setAffinityOS) where
import Control.Monad
import Foreign
import Foreign.C
import System.IO.Error
foreign import ccall unsafe "pin_pthread" pin_pthread :: CInt -> IO Errno