Skip to content

Instantly share code, notes, and snippets.

View puffnfresh's full-sized avatar

Brian McKenna puffnfresh

View GitHub Profile
@puffnfresh
puffnfresh / nix-example.sh
Last active February 22, 2023 04:22
Using Nix from AUR on Arch Linux
#!/bin/sh
## Or use an AUR helper, e.g.
## sudo aura -A nix
sudo pacman -S base-devel git
git clone https://aur.archlinux.org/nix.git
cd nix
makepkg -s
sudo pacman -U nix-*.pkg.tar.xz
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DeriveFoldable #-}
import Data.Foldable
class GetKeys a where
getKeys :: a -> [Char]
instance Foldable t => GetKeys (t Char) where
getKeys = toList
{-# LANGUAGE TupleSections #-}
import Control.Lens
data Expr
= Var String
| App Expr Expr
| Lam String Expr
deriving Show
@puffnfresh
puffnfresh / SizedExample.agda
Last active December 12, 2016 05:11
Small example of getting compositionality of termination proofs using copatterns and sized types
module SizedExample where
open import Data.List using (List; []; _∷_)
open import Data.Product using (_×_; proj₁; proj₂)
open import Size using (Size; Size<_)
record Stream (i : Size) (A : Set) : Set where
coinductive
field
head : A
@puffnfresh
puffnfresh / Main.agda
Last active July 30, 2017 01:59
cat in Agda
module Main where
import IO.Primitive as Prim
open import Coinduction
open import Data.Unit
open import IO
cat : IO ⊤
cat = ♯ getContents >>= (\cs → ♯ (putStr∞ cs))
@puffnfresh
puffnfresh / Main.agda
Created December 6, 2016 23:47
Non-terminating IO data type in Agda
module Main where
import IO.Primitive as Prim
open import Data.Unit
open import IO
open import Coinduction
nonTerminatingIO : IO ⊤
nonTerminatingIO = ♯ nonTerminatingIO >> ♯ return tt
@puffnfresh
puffnfresh / async.scala
Created November 29, 2016 23:21
async combinator using scalaz IO
package scalaz
import java.net.{ InetSocketAddress, StandardSocketOptions }
import java.nio.ByteBuffer
import java.nio.channels.{ AsynchronousFileChannel, AsynchronousServerSocketChannel, AsynchronousSocketChannel, CompletionHandler }
import java.nio.charset.StandardCharsets.UTF_8
import java.nio.charset.{ Charset, CharsetEncoder }
import java.nio.file.{ Path, OpenOption, StandardOpenOption }
import java.util.Date
@puffnfresh
puffnfresh / Example.scala
Created October 29, 2016 01:40
Predef identity not inlined
object Example {
@inline final def id[A](a: A): A =
a
final def example1: List[Int] =
Nil
final def example2: List[Int] =
id(Nil)
class Witness[A, B >: A] {
@inline final def apply(a: A): B = a
}
object Witness {
final val example: List[Int] =
(new Witness[List[Nothing], List[Int]])(Nil)
}
// scalac -Yinline -optimise Witness.scala
sealed trait Nat {
def isZero: Boolean
def pred: Nat
@annotation.tailrec final def countDown(xs: List[Nat]): List[Nat] = {
val next: List[Nat] =
this :: xs
if (isZero)
next
else