Skip to content

Instantly share code, notes, and snippets.

@jbrownson
jbrownson / adts.ts
Created January 5, 2016 18:14
ADTs in Javascript using functions
export type Disjunction<T, U> = <Z>(a: (t: T) => Z, b: (u: U) => Z) => Z
export type Disjunction3<T, U, V> = Disjunction<T, Disjunction<U, V>>
export type Disjunction4<T, U, V, W> = Disjunction3<T, U, Disjunction<V, W>>
export type List<T> = Disjunction<{head: T, tail: List<T>}, {}>
export type Maybe<T> = Disjunction<T, {}>
export function listFromArray<T>(array: T[]): List<T> {
return <Z>(a: (x: {head: T, tail: List<T>}) => Z, b: () => Z) =>
array.length == 0
? b()
@jbrownson
jbrownson / infinite-type.purs
Created October 15, 2015 12:43
infinite type error using purescript-react
module Main where
import Prelude (($), unit, bind, pure)
import React (createClass, spec, getProps)
import qualified React.DOM as D
import qualified React.DOM.Props as P
f = createClass $ spec unit \this -> do
x <- getProps this
y <- x 42
import Data.List
import Data.Maybe
import Control.Monad.State
import Control.Monad.List
import Control.Monad.Writer
import Control.Monad.Trans.Maybe
boardSize = 3
data XO = X | O deriving (Show, Eq)
// algebra - the study of mathematical symbols and the rules for manipulating these symbols
// [https://en.wikipedia.org/wiki/Algebra]
// composition - combining parts or elements to form a whole.
// [http://dictionary.reference.com/browse/composition]
// algebraic data type - a kind of composite type, i.e. a type formed by combining other types
// [https://en.wikipedia.org/wiki/Algebraic_data_type]
enum One {
func add5(i: Int) -> Int { return i + 5 }
add5(42)
// Arrays: The Hard Way
func add5ArrayTheHardWay(array: [Int]) -> [Int] {
var arrayAdd5 = [Int]()
for i in array { arrayAdd5.append(add5(i)) }
return arrayAdd5
(ns pente.core)
(defn new-game [size]
{:board (assoc-in (vec (repeat size (vec (repeat size nil))))
(repeat 2 (int (Math/floor (/ size 2))))
:white)
:turn :black
:captures {:white 0 :black 0}})
(def not-color {:white :black :black :white})
/usr/bin/env perl -e use XML::Parser
/usr/bin/env perl -e use XML::Parser
==> Downloading http://ftp.gnome.org/pub/GNOME/sources/gtkmm/3.6/gtkmm-3.6.0.tar.xz
Already downloaded: /Library/Caches/Homebrew/gtkmm3-3.6.0.tar.xz
xz -dc "/Library/Caches/Homebrew/gtkmm3-3.6.0.tar.xz" | /usr/bin/tar xf -
==> ./configure --disable-dependency-tracking --prefix=/usr/local/Cellar/gtkmm3/3.6.0
./configure --disable-dependency-tracking --prefix=/usr/local/Cellar/gtkmm3/3.6.0
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... build/install-sh -c -d
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by glib configure 2.30.2, which was
generated by GNU Autoconf 2.68. Invocation command line was
$ ./configure --disable-dependency-tracking --disable-rebuilds --prefix=/usr/local/Cellar/glib/2.30.2 --with-libiconv=gnu --disable-dtrace --disable-debug
## --------- ##
## Platform. ##