Skip to content

Instantly share code, notes, and snippets.

Brian McKenna puffnfresh

Block or report user

Report or block puffnfresh

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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 / default.nix
Last active Jun 14, 2019
ghc not found patch for haskell.nix
View default.nix
{ pkgs ? import <nixpkgs> {} }:
haskell = import (builtins.fetchTarball { 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.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 / 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/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")
View Scott.hs
{-# LANGUAGE ScopedTypeVariables, Rank2Types #-}
module ScottEncoding where
import Prelude hiding (null, length, map, foldl, foldr, take, fst, snd, curry, uncurry, concat, zip, (++))
newtype SMaybe a
= SMaybe { runMaybe :: forall b. b -> (a -> b) -> b }
newtype SList a
= SList { runList :: forall b. b -> (a -> SList a -> b) -> b }
View ghci
Prelude Language.Haskell.TH.Cleanup Generics.Deriving.TH
λ data X = A | B
Prelude Language.Haskell.TH.Cleanup Generics.Deriving.TH
λ putStrLn $(simplifiedTH =<< deriveAll0 ''X)
instance Generic (X :: *)
where type Rep (X :: *) = D1 ('MetaData "X" "Ghci3" "interactive" 'False) (:+: (C1 ('MetaCons "A" 'PrefixI 'False) U1) (C1 ('MetaCons "B" 'PrefixI 'False) U1))
from val_0 = case val_0 of
y_1 -> M1 (case y_1 of
A -> L1 (M1 U1)
B -> R1 (M1 U1))
View ReverseFunction.agda
open import Data.List
open import Data.List.Properties
open import Relation.Binary.PropositionalEquality
record ReverseFunction : Set₁ where
f : {A} List A List A
rev : {A} (xs ys : List A) f (xs ++ ys) ≡ f ys ++ f xs
sing : {A} (x : A) f (x ∷ []) ≡ x ∷ []
puffnfresh / Example.hs
Created Mar 14, 2018
Prism' as a smart constructor
View Example.hs
module Example (Example, example) where
import Data.Functor (($>))
import Control.Lens (Prism', prism')
import Control.Monad (guard)
data Example
= Example String
deriving (Eq, Ord, Show)
View MonoidObject.hs
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
import Control.Applicative
import Control.Comonad
import Control.Monad
import Data.Functor.Compose
import Data.Functor.Contravariant
import qualified Data.Functor.Contravariant.Day as Contravariant
You can’t perform that action at this time.