Skip to content

Instantly share code, notes, and snippets.

$$ \tag*{r = f(x)} \cfrac {\Gamma \vdash f: (A) \rightarrow B, x: T, r: R} {(A) \rightarrow B <: (T) \rightarrow R} $$

@andyfriesen
andyfriesen / BUCK
Created July 30, 2023 17:20
Trying to work out how to get a single mega-compilation-database out of Buck. This is a pretty naive approach, but I think it works?
# compdb/BUCK
python_bootstrap_binary(
name = "combine_compdbs",
main = "combine_compdbs.py",
visibility = ["PUBLIC"]
)
@andyfriesen
andyfriesen / TestableIO.hs
Last active August 10, 2021 18:25
Tiny example showing how to force your Haskell code to be 100% deterministic under unit tests
{-# LANGUAGE FlexibleInstances #-}
module Main where
import Control.Applicative ((<$>))
import Control.Monad.State.Lazy as S
class Monad m => World m where
writeLine :: String -> m ()
instance World IO where
<html>
<canvas id="canvas" width="256" height="256" />
<script>
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
ctx.fillStyle = 'black';
ctx.fillRect(0, 0, 256, 256);
ctx.fillStyle = 'white';
{-# LANGUAGE RecordWildCards #-}
module Promise where
import Control.Monad
import Data.IORef
import Data.Maybe
data Status
= Pending
module Clock = {
include ReactRe.Component.Stateful;
let name = "Clock";
type props = ();
type state = {now: Js_date.t, timerID: option Js_global.intervalId};
let getInitialState () => {
{ now: Js_date.make (), timerID: None };
};
use std::ops::{Add, Sub};
#[derive(Copy, Debug)]
pub struct Rect<T> {
pub left: T,
pub top: T,
pub right: T,
pub bottom: T
}
@andyfriesen
andyfriesen / hurbl.md
Created July 12, 2016 00:45
A quick example of why STM is amazing

Say we want to spin off threads every so often, but we also need the ability to wait until they all go away before exiting the application.

In Haskell, we can do this naive thing:

main = do
    count <- newTVarIO 0
    
 let spawnThread action = do
#include <iostream>
#define DEFPROP(name, type_) type_ name;
#define S(_) \
_(foo, int); \
_(bar, float)
struct MyStruct {
@andyfriesen
andyfriesen / pyconfig.h
Created September 18, 2013 02:44
pyconfig for Python 3.1.2
#ifndef Py_CONFIG_H
#define Py_CONFIG_H
/* pyconfig.h. NOT Generated automatically by configure.
This is a manually maintained version used for the Watcom,
Borland and Microsoft Visual C++ compilers. It is a
standard part of the Python distribution.
WINDOWS DEFINES: