Skip to content

Instantly share code, notes, and snippets.

View puffnfresh's full-sized avatar

Brian McKenna puffnfresh

View GitHub Profile
{ dmenu, fetchgit }:
dmenu.overrideAttrs (attrs: {
patches = [ ];
src = fetchgit {
url = "https://git.sr.ht/~mil/sxmo-dmenu";
rev = "5.0.10";
sha256 = "1qnwrfx33z4iqvd7m06bf4rlbjxsvxy4m9lrypc5gnwmanl72zcb";
};
})
module Primes where
open import Level using (_⊔_)
open import Coinduction
open import Function
open import Data.Empty
open import Data.Unit
open import Data.Nat
open import Data.Nat.Properties
open import Data.Nat.Divisibility
with import <nixpkgs> { };
package:
haskell.lib.overrideCabal package (p: {
isLibrary = false;
enableSharedExecutables = false;
postInstall = ''
rm -r $out/lib $out/share
'';
})
@puffnfresh
puffnfresh / Traversal1.hs
Created July 16, 2021 13:01
Get a Traversal from a Traversal1
{-# LANGUAGE RankNTypes #-}
import Control.Lens
import Data.Functor.Apply
traversal1
:: Traversal1 s t a b
-> Traversal s t a b
traversal1 t f =
unwrapApplicative . t (WrapApplicative . f)
@puffnfresh
puffnfresh / FP.java
Last active April 27, 2021 01:03
Writing functions once, using Cubix. FP.java, FP.py and FP.js are generated by running Main.hs
public class FP
{
public static <A> A identity (A a)
{
return a;
}
public static <A, B> A constant (A a, B b)
{
return a;
}
@puffnfresh
puffnfresh / Compose.agda
Last active February 23, 2021 03:44
Functors compose
module Compose where
open import Level
open import Function
open import Relation.Binary.PropositionalEquality
record Functor {α} (T : Set α → Set α) : Set (suc α) where
field
map : ∀ {A B : Set α} → (A → B) → T A → T B
identity : ∀ {A : Set α} → map id ≡ id {A = T A}
How do we add extra information to a tree? This has been called [The
AST Typing
Problem](http://blog.ezyang.com/2013/05/the-ast-typing-problem/).
After being hit with this problem in Roy's new type-inference engine,
I tried figuring out how to represent the algorithm. I eventually
realised that it looked like a comonadic operation. Turns out it's
been done before but I couldn't find any complete example.
Below is some literate Haskell to show how to use the Cofree Comonad
@puffnfresh
puffnfresh / AlaCarte.hs
Created April 1, 2014 22:46
Coproduct to combine algebras for a free monad interpreter.
module AlaCarte where
-- Control.Monad.Free
data Free f a = Free (f (Free f a)) | Pure a
instance Functor f => Monad (Free f) where
Pure a >>= f = f a
Free r >>= f = Free (fmap (>>= f) r)
return = Pure
@puffnfresh
puffnfresh / chromebook-nix.sh
Last active October 28, 2020 03:06
Installation script for Nix on ChromeOS
#!/bin/sh
sudo mount -o remount,exec /tmp
if [ -x /usr/local/nixstrap/proot-x86_64 ] && [ -h ~/.nix-profile ]; then
echo "Launching shell with nix-* tools!"
exec /usr/local/nixstrap/proot-x86_64 -b /usr/local/nixstrap/nix-1.8-x86_64-linux:/nix bash --init-file ~/.nix-profile/etc/profile.d/nix.sh
fi
set -e
@puffnfresh
puffnfresh / npm_chpwd_hook.sh
Created November 27, 2012 01:17
Adds node_modules/.bin to the PATH (zsh)
# Adds node_modules/.bin to the PATH
npm_chpwd_hook() {
if [ -n "${PRENPMPATH+x}" ]; then
PATH=$PRENPMPATH
unset PRENPMPATH
fi
if [ -f package.json ]; then
PRENPMPATH=$PATH
PATH=$(npm bin):$PATH
fi