Skip to content

Instantly share code, notes, and snippets.

View evincarofautumn's full-sized avatar

Jon Purdy evincarofautumn

View GitHub Profile
@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 / 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 / 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

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 / 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)
-- ===
@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 / 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 / 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 / gist:0917acd8d671e7ef9b9a
Created February 24, 2015 21:07
Diagnostic output for XamarinAndroid project in Mobile-App-Performance benchmark
Building: Shared (Debug)
Building: XamarinAndroid (Debug)
Build started 2/24/2015 1:06:44 PM.
__________________________________________________
Project "/Users/jonathanpurdy/Projects/Mobile-App-Performance/Xamarin/XamarinAndroid/XamarinAndroid.csproj" (Build target(s)):
Initial Properties:
__CF_USER_TEXT_ENCODING = 0x1F5:0:0
Git submodules updated successfully
/Applications/Xcode.app/Contents/Developer/usr/bin/make all-recursive
Making all in po
Making all in mcs
make[3]: Nothing to be done for `all-am'.
Making all in libgc
Making all in m4
make[3]: Nothing to be done for `all'.
Making all in include
Making all in private