Skip to content

Instantly share code, notes, and snippets.

@GeoffChurch
GeoffChurch / diagonalApply.hs
Last active March 7, 2021 16:28
"Diagonalized" version of <*> for lists, which reaches every finitely reachable application
ap :: [a -> b] -> [a] -> [b]
ap fs xs = go1 ([], fs) ([], xs)
where
go1 (fs, []) (_, xs) = [f x | x <- xs, f <- fs] -- No more fs: roundrobin seen fs on unseen xs.
go1 fs@(_, f : _) xs@(seenxs, _) = [f x | x <- seenxs] ++ go2 (step fs) xs -- Apply next f to seen xs and recur.
go2 (_, fs) (xs, []) = [f x | f <- fs, x <- xs] -- No more xs: roundrobin seen xs on unseen fs.
go2 fs@(seenfs, _) xs@(_, x : _) = [f x | f <- seenfs] ++ go1 fs (step xs) -- Apply seen fs to next x and recur.
step (seen, cur : unseen) = (cur : seen, unseen) -- Mark current element as seen.
-- E.g. to generate all triples
@GeoffChurch
GeoffChurch / zip.hs
Last active December 15, 2020 14:40
zip in terms of foldr
import Prelude hiding (zip)
-- `zip` accepts the first list and lazily returns a
-- function that accepts the second list and lazily
-- returns the list of pairs, so this implementation
-- is lazy in both arguments.
zip :: [a] -> [b] -> [(a, b)]
zip =
foldr
zipxs
@GeoffChurch
GeoffChurch / settings.json
Last active August 7, 2021 00:48
VS Code settings
{
"editor.acceptSuggestionOnEnter": "off",
"editor.selectionClipboard": false, // Disable middle-click paste.
"telemetry.enableTelemetry": false,
"telemetry.enableCrashReporter": false,
"workbench.startupEditor": "none",
"window.zoomLevel": 3,
"window.restoreFullscreen": true,
"workbench.statusBar.visible": true,
"workbench.activityBar.visible": false,
@GeoffChurch
GeoffChurch / .emacs
Last active May 2, 2017 20:16
.emacs
(menu-bar-mode -1)
(setq inhibit-startup-screen t)
(setq inhibit-startup-echo-area-message "l")
(setq initial-major-mode 'fundamental-mode)
(setq initial-scratch-message nil)
(setq auto-save-default nil)
(setq make-backup-files nil)
(require 'package)
;;(add-to-list 'package-archives
@GeoffChurch
GeoffChurch / n-byte-wise_seq2seq.py
Last active February 21, 2016 04:36 — forked from karpathy/min-char-rnn.py
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy). Edited by Geoffrey Churchill
BSD License
"""
import numpy as np
from sys import argv
try:
num_steps=int(argv[3])
except IndexError: