Skip to content

Instantly share code, notes, and snippets.

Jaden Geller JadenGeller

Block or report user

Report or block JadenGeller

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@JadenGeller
JadenGeller / NatSum.idr
Last active Nov 28, 2017
Dependent sums subsume algebraic data types in presence of enums
View NatSum.idr
%hide Nat
%hide Nat.S
%hide Nat.Z
function : List Type -> Type -> Type
function [] b = b
function (a :: as) b = a -> function as b
infixr 10 *->
@JadenGeller
JadenGeller / Default.swift
Last active Nov 7, 2017
Optional Default Raw
View Default.swift
extension Optional {
subscript (default value: Wrapped) -> Wrapped {
get {
return self ?? value
}
set {
self = newValue
}
}
}
View DynamicDict.py
#!/usr/bin/python
import string
class DynamicDict:
def __init__(self, function):
self._function = function
def __getitem__(self, key):
return self._function(key)
View Spiral.idr
import Data.Vect
Matrix : Nat -> Nat -> Type -> Type
Matrix r c a = Vect r (Vect c a)
unrotate : Matrix r c a -> Matrix c r a
unrotate = reverse . transpose
spiral : Matrix r c a -> Vect (r * c) a
spiral {r=Z} [] = []
View Mean.swift
infix operator : AdditionPrecedence
struct Mean: ExpressibleByFloatLiteral, ExpressibleByIntegerLiteral {
private let total: Float
private let count: Int
private init(total: Float, count: Int) {
self.total = total
self.count = count
}
@JadenGeller
JadenGeller / OpenClose.js
Last active May 7, 2017
Lambda Calculus w/o Parenthesis
View OpenClose.js
//// Implementation
OPEN = Symbol("open")
CLOSE = Symbol("close")
function run(program) {
function applyUntilClose(continuation = x => x) {
function iter(f) {
if (f === OPEN) {
return applyUntilClose(r => iter(r))
} else if (f == CLOSE) {
throw new Error("Unexpected empty grouping")
@JadenGeller
JadenGeller / Shadow.js
Last active May 6, 2017
Shadowing Dictionary
View Shadow.js
function Shadow() {
return new Proxy({}, {
get: function (target, name) {
if (name in target) {
let stack = target[name];
return stack[stack.length - 1];
} else {
return undefined;
}
},
View Scope.js
function Scope(parent = {}) {
return new Proxy({}, {
get: function(target, name) {
return name in target ?
target[name] :
parent[name];
},
has: function (target, name) {
return name in target || name in parent;
}
@JadenGeller
JadenGeller / Change.py
Last active Nov 5, 2017
Monadic Python (requires Python interpreter that supports deep-copying generators, like pypy)
View Change.py
############## This is deprecated.
### NOTICE ### Use the NEW VERSION on GitHub:
############## https://github.com/JadenGeller/Guac
# Similiar to this Hasekell program: https://gist.github.com/JadenGeller/faef08a0278d41c0dcc682bca36a9ef8#file-solution-hs
@monadic(ListMonad)
def make_change(amount_still_owed, possible_coins):
change = []
while amount_still_owed > 0 and possible_coins:
give_min_coin = yield [True, False] # nondeterministic choice, aka try both
@JadenGeller
JadenGeller / YieldThrows.py
Created May 3, 2017
Using coroutines for throwing errors
View YieldThrows.py
import math
# use `yield` as equivalent to Swift's
# - `try` keyword
def sqrt(x): # throwing
if x < 0:
yield Exception()
return math.sqrt(x)
You can’t perform that action at this time.