Skip to content

Instantly share code, notes, and snippets.

@puffnfresh
puffnfresh / FP.java
Last active Apr 27, 2021
Writing functions once, using Cubix. FP.java, FP.py and FP.js are generated by running Main.hs
View FP.java
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 / lua-launchdarkly.c
Last active Jul 13, 2020
Binding LaunchDarkly C SDK to Lua
View lua-launchdarkly.c
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <launchdarkly/api.h>
#include <openssl/sha.h>
#include <lua.h>
@puffnfresh
puffnfresh / not.fgg
Last active Jun 17, 2020
Encoding Booleans in Featherweight Generic Go
View not.fgg
package main;
type Any(type) interface { };
type Name(type a Any()) interface {
value(type)() a
};
type Value(type a Any()) struct {
value a
View agda-blocks.hs
#!/usr/bin/env nix-shell
#!nix-shell -p "haskellPackages.ghcWithPackages (p: [ p.pandoc p.pandoc-types ])" -i runhaskell
{-# LANGUAGE OverloadedStrings #-}
import Text.Pandoc.JSON
import Text.Pandoc.Shared (tshow)
import Data.Text as T
main :: IO ()
@puffnfresh
puffnfresh / sbt.log
Created Jul 15, 2019
ClassBType.info not yet assigned
View sbt.log
java.lang.AssertionError: assertion failed: ClassBType.info not yet assigned: Lcom/atlassian/marketplace/http/rest/v2/
representations/RepresentationFactory$;
at scala.Predef$.assert(Predef.scala:170)
at scala.tools.nsc.backend.jvm.BTypes$ClassBType.info(BTypes.scala:820)
at scala.tools.nsc.backend.jvm.BTypes$ClassBType.isNestedClass(BTypes.scala:883)
at scala.tools.nsc.backend.jvm.BCodeHelpers$BCInnerClassGen$class.toTypeKind(BCodeHelpers.scala:355)
at scala.tools.nsc.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.toTypeKind(BCodeSkelBuilder.scala:50)
at scala.tools.nsc.backend.jvm.BCodeSkelBuilder$PlainSkelBuilder.symInfoTK(BCodeSkelBuilder.scala:82)
at scala.tools.nsc.backend.jvm.BCodeBodyBuilder$PlainBodyBuilder.ge
View doom2nix.el
#!/usr/bin/env nix-shell
#! nix-shell -i "emacs --batch -l $HOME/.emacs.d/core/core.el -l $HOME/.emacs.d/core/core-packages.el -l $HOME/.emacs.d/core/autoload/packages.el -l" -p "emacsWithPackages (p: [ p.persistent-soft p.use-package p.quelpa p.async ])"
;; doom-module-load-path
(princ "p:\n")
(princ "let checked = n:\n")
(princ " let p' = p.${n} or null;\n")
(princ " in if p'.meta.broken or false then null else p';\n")
(princ "in\n")
@puffnfresh
puffnfresh / default.nix
Last active Jun 14, 2019
ghc not found patch for haskell.nix
View default.nix
{ pkgs ? import <nixpkgs> {} }:
let
haskell = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) { inherit pkgs; };
happyHack = config:
let inherit (config.hsPkgs) happy;
in "export happy_datadir=${happy.components.exes.happy}/share/${builtins.currentSystem}-ghc-${config.compiler.version}/${happy.identifier.name}-${happy.identifier.version}";
pkgSet = haskell.mkCabalProjectPkgSet {
View LoadedData.ts
type LoadedData<A> =
<B>(f: (a: A) => B, g: (e: Error) => B, b: B) => B;
function loaded<A>(a: A): LoadedData<A> {
return <B>(f: (a: A) => B, error: (e: Error) => B, empty: B) => f(a);
}
function error<A>(e: Error): LoadedData<A> {
return <B>(success: (a: A) => B, f: (e: Error) => B, empty: B) => f(e);
}
@puffnfresh
puffnfresh / Payments.hs
Created Mar 12, 2019 — forked from friedbrice/Payments.hs
Java6-compatible algebraic data types via Church-Scott Encoding
View Payments.hs
module Payments where
data Customer = Customer { name :: String, age :: Int } deriving (Eq, Ord, Show)
-- I know partial record fields is an anti-pattern, but who's counting?
data Payment
= Cash { customer :: Customer, amount :: Double }
| Credit { customer :: Customer, amount :: Double, cardNumber :: Int }
| Check { customer :: Customer, amount :: Double, routingNumber :: Int, accountNumber :: Int }
deriving (Eq, Ord, Show)
View spacemacs2nix.el
#!/usr/bin/env nix-shell
#! nix-shell -i "emacs --batch -l $HOME/.emacs.d/core/core-load-paths.el -l" -p emacs26-nox
(require 'core-configuration-layer)
(configuration-layer/discover-layers)
(configuration-layer/make-all-packages nil)
(princ "p:\n")
(princ "let checked = n:\n")
(princ " let p' = p.${n} or null;\n")
(princ " in if p'.meta.broken or false then null else p';\n")