Skip to content

Instantly share code, notes, and snippets.

View hallettj's full-sized avatar

Jesse Hallett hallettj

View GitHub Profile
@hallettj
hallettj / array_monad.js
Created March 28, 2014 08:03
Trying to apply ES6 generators to create monad comprehensions. Unfortunately it looks like this will not work with monads that contain multiple values, such as arrays.
/*
* The implementation
*/
function du(comprehension) {
return function(/* args */) {
var gen = comprehension.apply(null, arguments)
return next();
function next(v) {

Keybase proof

I hereby claim:

  • I am hallettj on github.
  • I am hallettj (https://keybase.io/hallettj) on keybase.
  • I have a public key whose fingerprint is A378 B079 9F05 93C0 B499 DD02 8FB4 E35F E86B 913B

To claim this, I am signing this object:

@hallettj
hallettj / Logic.idr
Created April 18, 2014 20:56
basic mathematical logic in Idris
module Logic
infixr 1 ==>
(==>) : Bool -> Bool -> Bool
False ==> _ = True
True ==> x = x
data Exists : (A : Type) -> (P : A -> Bool) -> Type where
exists : {A : Type} -> {P : A -> Bool} -> (a : A) -> so (P a) -> Exists A P
@hallettj
hallettj / Cat.lidr
Last active April 2, 2018 15:05
description of category laws in Idris
# Category Theory proofs in Idris
Idris is a language with dependent types, and is similar to Agda.
What distinguishes Idris is that it is intended to be a general-purpose language first,
and a theorem prover second.
To that end it supports optional totality checking
and features to support writing DSLs:
type classes,
do notation,
monad comprehensions (i.e., a more general form of list comprehension),
@hallettj
hallettj / tree-no_classes.js
Last active October 22, 2021 15:14
Algebraic data type in Javascript with Flow
/* @flow */
type Tree<T> =
| { type: "Node", value: T, left: Tree<T>, right: Tree<T> }
| { type: "EmptyTree" }
function find<T>(p: (v: T) => boolean, t: Tree<T>): T | void {
var l, v
if (t.type === "Node") {
@hallettj
hallettj / quickstart.markdown
Last active August 29, 2015 14:17
JavaScript development quickstart

Quickstart

Get a development environment and project scaffold set up in a jiffy.

Development environment

First install node and npm. There are instructions here:

@hallettj
hallettj / gulpfile.js
Created April 23, 2015 01:37
Gulpfile configured for use with Babel, Wepback, and Flow
var execFile = require('child_process').execFile;
var flow = require('flow-bin');
var gulp = require('gulp');
var path = require('path')
var util = require('gulp-util');
var webpack = require('webpack');
var gulpWebpack = require('gulp-webpack');
var _ = require('lodash');
gulp.task('build', ['flow:check'], function() {
@hallettj
hallettj / 01_notes.md
Last active September 22, 2015 00:48
Changes required to adapt a React app to run in Electron
import Data.List (groupBy, sort, sortOn, transpose)
type Vector = [Double]
type Matrix = [Vector] -- two-dimensional matrix
{- Distance functions -}
-- type for a distance function
type Distance = Vector -> Vector -> Double
@hallettj
hallettj / adt.js
Last active March 21, 2019 12:56
Proposed implementation of GADTs with Javascript and Flow
/*
* `match` is a helper function for writing pattern matches on types that are
* implemented using Scott encoding.
*
* @flow
*/
export function match<A,B>(matcher: A): (match: (matcher: A) => B) => B {
return match => match(matcher)
}