Skip to content

Instantly share code, notes, and snippets.

View evincarofautumn's full-sized avatar

Jon Purdy evincarofautumn

View GitHub Profile
@evincarofautumn
evincarofautumn / most-included.pl
Last active August 29, 2015 14:21
Finds the largest headers most included by other headers.
#!/usr/bin/env perl
# Usage: ./most-included.pl $(find mono -name '*.h')
use warnings;
use strict;
my %forward = ();
while (<>) {
@evincarofautumn
evincarofautumn / permissions.cpp
Created July 28, 2015 22:21
Ideas about enforcing permissions in C++
#include <iostream>
using namespace std;
#define CHECK_ASSUMPTIONS 0
#if CHECK_ASSUMPTIONS
#define ASSUMING(...) __VA_ARGS__
#else
#define ASSUMING(...)
#endif
@evincarofautumn
evincarofautumn / linux-i686.toolchain.cmake
Created December 1, 2015 20:41
32-bit cross-compilation with CMake for rr
# cmake CMAKE_TOOLCHAIN_FILE=".../linux-i686.toolchain.cmake" .../rr
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_ARCHITECTURE i686)
set(CMAKE_C_COMPILER gcc -m32)
set(CMAKE_CXX_COMPILER g++ -m32)
@evincarofautumn
evincarofautumn / InlineDoBind.md
Last active April 20, 2023 21:16
Thoughts on an InlineDoBind extension

Thoughts on an InlineDoBind extension

An expression beginning with a left arrow (<-) inside a do block statement is desugared to a monadic binding. This is syntactically a superset of existing Haskell, including extensions. It admits a clean notation that subsumes existing patterns and comes with few downsides.

Examples

do
  f (<- x) (<- y)
-- ===

Grammar of Kitten

This is an annotated EBNF grammar of the latest rewrite of Kitten. Items marked with a dagger (†) are explained in the surrounding prose, not in EBNF.

Source Locations

The source column of a token is the offset to its first character within the line in which it appears. The indentation of a line is the source column of the first token in the line. Tab characters are illegal.

Layout

@evincarofautumn
evincarofautumn / factoring-and-generalizing-in-haskell.md
Last active July 30, 2016 19:43
Factoring and Generalizing in Haskell

Factoring and Generalizing in Haskell

Suppose we want to write a simple function f to calculate the sum of the squares of the even numbers in a list. We can start by writing down some examples of expected inputs and outputs.

f [] == 0
f [2] == 4
f [3] == 0
f [4] == 16
f [2, 4] == 20
@evincarofautumn
evincarofautumn / ContInst.hs
Created November 7, 2016 13:21
Playing with typeclass instances for continuations
import Control.Monad.Trans.Cont
import GHC.Exts (IsString(..))
instance (Num a) => Num (ContT r m a) where
fromInteger x = ContT (\k -> k (fromInteger x))
{-
fromInteger = ContT . flip ($) . fromInteger
-}
@evincarofautumn
evincarofautumn / PureMonad.hs
Created January 25, 2017 15:16
Ironically named PureMonad class
class (Monad m) => PureMonad m where
run :: m a -> a
instance PureMonad Maybe where
run = fromJust
instance PureMonad (Either a) where
run = fromRight
instance PureMonad [] where
@evincarofautumn
evincarofautumn / lens.ktn
Last active February 8, 2017 10:27
Translating the lens tutorial to Kitten
// data Atom = Atom { _element :: String, _point :: Point }
type Atom:
case mkatom:
_element as (Text)
_point as (Point)
// data Point = Point { _x :: Double, _y :: Double }
type Point:
case mkpoint:
_x as (Float64)
@evincarofautumn
evincarofautumn / constraints.ktn
Last active February 10, 2017 02:24
Trait constraints and assumptions in Kitten
// A constraint could be sugar for a permission:
//
// “where (foo<T>)” → “+Defined(foo<T>)”
// “where (<A, B> map<F<_>, A, B>)” → “+Defined(<A, B> map<F<_>, A, B>)”
//
// It looks like effects and coeffects can both be represented with permissions because all terms are functions.
trait (<)<T> (T, T -> Bool)
trait zero<T> (-> T)
trait neg<T> (T -> T)