Skip to content

Instantly share code, notes, and snippets.

@mvitocruz
mvitocruz / shift_reset.ml
Created August 16, 2012 01:24
Delimited continuation exercises
(* Exercises from "Introduction to programming with shift and reset" by Kenichi Asai and Oleg Kiselyov
http://pllab.is.ocha.ac.jp/~asai/cw2011tutorial/main-e.pdf *)
(* Exercise 1: Identify the next expression to be evaluated, its type, and result type of the continuation.
(1) 5 * (2 * 3 + 3 * 4)
next expression to be evaluated is [2 * 3], type is int, continuation result is int
(2) (if 2 = 3 then "hello" else "hi") ^ " world"
next expression [2 = 3], type bool, continuation result type string
(3) fst (let x = 1 + 2 in (x, x))
@mvitocruz
mvitocruz / test.R
Created February 11, 2012 04:18
Fake pass-by-reference in R
# faking pass-by-reference in R by manipulating environments
swap <- function(x, y) {
xname <- deparse(substitute(x))
yname <- deparse(substitute(y))
xval <- x
yval <- y
# dynamic scope is more useful so can't use parent.env(environment())
parent <- parent.frame()
@mvitocruz
mvitocruz / poly.ml
Created May 18, 2011 18:56
Polymorphic variant type-inference test
module M :
sig
type smaller = [ `X ]
type larger = [ `X | `Y ]
type 'a t
val with_smaller : (smaller t -> 'a) -> 'a
val with_larger : (larger t -> 'a) -> 'a
@mvitocruz
mvitocruz / git-workflow.txt
Created April 28, 2011 18:26
Proposed shared repo workflow
Assuming new features are supposed to be pushed to origin/master.
Aims:
* keep history simple (linear if possible, but make it easy to see
multi-commit features)
* use pull requests for review (but person making request is responsible
for merging/pushing)
* try to minimize branch shuffling during the process
1) Make sure you are up to date: