Skip to content

Instantly share code, notes, and snippets.

View thoferon's full-sized avatar

Tom Feron thoferon

View GitHub Profile
@thoferon
thoferon / Module.hs
Created February 4, 2020 06:14
haskell-nix-setup
module Module
( secretNumber
) where
secretNumber :: Int
secretNumber = 4
@thoferon
thoferon / demo.cabal
Created February 4, 2020 06:14
haskell-nix-setup
cabal-version: 1.12
name: demo
version: 0.9.0
author: Tom Feron
maintainer: Tom Feron
build-type: Simple
library
hs-source-dirs: src
ghc-options: -Wall
import _ from "underscore"
import game from "./sequentialActions.js"
function testInterpreter (program, inputs, accOutputs) {
switch (program.action) {
case "read":
const input = inputs[0]
const rest = inputs.slice(1)
return testInterpreter(program.next(input), rest, accOutputs)
import readline from "readline-sync"
function read () {
return {
action: "read",
next: pure,
}
}
function print (string) {
function numberField (key) {
return {
action: "numberField",
key,
}
}
function stringField (key) {
return {
action: "stringField",
import readline from "readline-sync"
// Side effects
class EffectfulImplementation {
getUserInput () {
return readline.question("> ")
}
listTodoItems () {
import parser from "./nonSequentialActions.js"
function generateDocumentation (parser) {
switch (parser.action) {
case "pure":
return null
case "stringField":
return { [parser.key]: "string" }
We couldn’t find that file to show.
@thoferon
thoferon / weighted_avg.sql
Last active August 29, 2015 14:23
Aggregate function weighted_avg for PostgreSQL
CREATE TYPE _weighted_avg_fraction
AS (num double precision, denom double precision);
CREATE OR REPLACE FUNCTION _weighted_avg_step (acc _weighted_avg_fraction,
val anyelement, pond anyelement) RETURNS _weighted_avg_fraction AS $$
BEGIN
RETURN (acc.num + val * pond, acc.denom + pond);
END;
$$ LANGUAGE plpgsql;
@thoferon
thoferon / predicated_list.v
Last active August 29, 2015 13:56
First attempt at predicated lists in Coq
Require Import Coq.Arith.Arith.
Section predicated_list.
Variable A : Type.
Variable bin_rel : A -> A -> Prop.
Hypothesis bin_rel_trans : forall a b c : A, bin_rel c b -> bin_rel b a -> bin_rel c a.
Set Implicit Arguments.