Skip to content

Instantly share code, notes, and snippets.

View ehrenmurdick's full-sized avatar

Ehren Murdick ehrenmurdick

View GitHub Profile
export function prop<O: { +[string]: mixed }, P: $Keys<O>>(
p: P
): (o: O) => $ElementType<O, P> {
return function(o) {
return o[p];
};
}
const f = prop('hi');
@ehrenmurdick
ehrenmurdick / .gitignore
Last active October 20, 2017 20:31
javascript promise playground
node_modules/
@ehrenmurdick
ehrenmurdick / church.spec.js
Last active September 13, 2017 17:34
Church encoding
const c = {
and: a => b => a(b)(c.false),
exp: m => n => n(m),
false: a => b => b,
isEQ: m => n => c.and(c.isLE(m)(n))(c.isLE(n)(m)),
isLE: m => n => c.isZ(c.sub(m)(n)),
isZ: n => n(x => c.false)(c.true),
mult: m => n => f => m(n(f)),
plus: m => n => f => x => m(f)(n(f)(x)),
pred: n => f => x => n(g => h => h(g(f)))(u => x)(u => u),

Triple equals in ruby is really interesting!

ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-darwin14]

You can check if an instance is in a class

class A
end

a = A.new
A === a
N = 10_000_000
class Foo
def initialize
@ary = (0..N).map { Object.new }
end
def a
# this is a closure that has captured self
define_singleton_method("O_o") {}
@ehrenmurdick
ehrenmurdick / holy_rusted_metal_batman.rb
Created March 27, 2017 22:16
closure memory leak in ruby
N = 10_000_000
class Foo
def initialize
@ary = (0..N).map { Object.new }
end
def a
return proc do
"hello"
@ehrenmurdick
ehrenmurdick / partial.hs
Created March 20, 2017 20:42
partial function application
-- in haskell, this is all abstracted away by syntactic sugar.
-- although the function type syntax probably looks familiar.
add :: Integer -> Integer -> Integer
add x y = x + y
-- can curry as well
inc = add 1
-- haskell functions all only have one arg in reality,
-- further arguments are always handled this way
class Contract
@created = {}
@fullfilled = {}
def self.create argument
@created[argument] = caller[0]
end
def self.fulfill argument
@fullfilled[argument] = caller[0]
type Result {
Value T
Err error
}