Skip to content

Instantly share code, notes, and snippets.

View dbp's full-sized avatar

Daniel Patterson dbp

View GitHub Profile
@dbp
dbp / printf.hs
Created October 13, 2018 19:08
c :: String -> ((String -> a) -> a)
c str = \k -> k str
d :: (String -> a) -> Int -> a
d = \k -> (\int -> k (show (int::Int)))
s :: (String -> a) -> String -> a
s = \k -> (\str -> k (str::String))
printf :: ((String -> IO ()) -> a) -> a
@dbp
dbp / circle.yml
Last active June 29, 2017 09:53
Haskell project with Stack on CircleCI
dependencies:
cache_directories:
- "~/.stack"
pre:
- wget https://github.com/commercialhaskell/stack/releases/download/v0.1.2.0/stack-0.1.2.0-x86_64-linux.gz -O /tmp/stack.gz
- gunzip /tmp/stack.gz && chmod +x /tmp/stack
- sudo mv /tmp/stack /usr/bin/stack
override:
- stack setup
- stack build
@dbp
dbp / gist:6246396
Created August 16, 2013 01:11
simple discrete scrolling
$(function () {
for(var i = 0; i < 10; i++) {
$("#active").append($("<div class='elem'>Block " + i + "</div>"));
}
$("#pointer").bind("mousedown", start);
});
function start(event) {
window.startpos = parseInt($("#pointer").css("top"));
$(document).bind("mousemove", drag);
@dbp
dbp / desugar-control.rkt
Created January 3, 2013 18:29
Desugaring control flow to letCC
;; Control flow
;; basically, we provide a shadowed '^throw continuation, and then see what
;; we are handed. if it is an error (ie, an exception), we see if it matches
;; what we are catching, and if it doesn't, we re-throw. Since we are out of
;; scope of the current try/catch, we will now pick up whatever exception
;; continuation is outside. note that this obviously requires the entire program
;; to be wrapped in a try/catch that matches on everything (which it is).
[CTry
(bdy mat cat els)
@dbp
dbp / cps.rkt
Created January 3, 2013 18:14
Python CPS core example
#lang plai-typed
(require "python-micro-syntax.rkt"
"python-helpers.rkt")
(define (run-cps [e : UExp])
(begin
(sym-reset)
(UApp (cps e) (UFn '^x (UId '^x)))))
@dbp
dbp / gist:3887084
Created October 14, 2012 02:50
impl eq
struct A {n: uint}
impl A: cmp::Eq {
pure fn eq(other: &A) -> bool {
self.n == other.n
}
pure fn ne(other: &A) -> bool {
!self.eq(other)
}
}
@dbp
dbp / gist:3861243
Created October 9, 2012 20:34
announce rustle
I'm announcing an initial version of an API search tool for Rust. It is inspired by the api search tool for haskell
called Hoogle (http://www.haskell.org/hoogle). It is very new (I started working on it a week ago), so it has a long
way to go, but for a taste of the kind of things it can currently do:
rustle> str -> uint
core::str::capacity - fn capacity(s: & const ~str) -> uint - Returns the number of single-byte characters the
string can hold without reallocating
core::str::char_len - fn char_len(s: & str) -> uint - Returns the number of characters that a string holds
core::str::len - fn len(s: & str) -> uint - Returns the string length/size in bytes not counting the null terminator
@dbp
dbp / gist:3856358
Created October 9, 2012 03:12
purity
struct C {mut d: ~[uint]}
fn main() {
let mut c = C {d: ~[1,2,3]};
f(&c);
}
fn f(x: &C) {
for x.d.each |e| {
io::println(~"a");
@dbp
dbp / copy_type.rs
Created October 7, 2012 21:55
instantiating copy type warning
fn main() {
let x = (~"a",~"b");
io::println(x.second());
}