Skip to content

Instantly share code, notes, and snippets.

@CoderPuppy
CoderPuppy / PHOAS.agda
Created July 11, 2023 11:17
Variant of Parametric Higher-Order Abstract Syntax where each binder binds a type.
{-# OPTIONS --overlapping-instances --instance-search-depth=10 #-}
module PHOAS where
open import Agda.Primitive
record Weakening1 {ℓ₁} {ℓ₂} (V : Set ℓ₁) (V' : Set ℓ₂) : Set (ℓ₁ ⊔ ℓ₂) where
field weaken : V → V'
record Weakening {ℓ₁} {ℓ₂} (V : Set ℓ₁) (V' : Set ℓ₂) : Set (ℓ₁ ⊔ ℓ₂) where
field weaken : V → V'
@CoderPuppy
CoderPuppy / Berardi.agda
Created July 21, 2022 01:15
Berardi's paradox in Agda
{-# OPTIONS --without-K #-}
module Berardi where
-- proof irrelevance from impredicativity and excluded middle
-- adapted from https://www.cs.princeton.edu/courses/archive/fall07/cos595/stdlib/html/Coq.Logic.Berardi.html
open import Agda.Primitive
{-# NO_UNIVERSE_CHECK #-}
@CoderPuppy
CoderPuppy / CoquandPaulin.agda
Created July 20, 2022 02:46
Formalization of paradox from Coquand and Paulin '88 in Agda
{-# OPTIONS --without-K #-}
module CoquandPaulin where
-- contradiction from non-strictly-positive type and impredicative sigma
-- possibly also "strong elimination", whatever that is
-- and impredicative identity
-- adapted from https://vilhelms.github.io/posts/why-must-inductive-types-be-strictly-positive/
-- originally from Inductively Defined Types by Thierry Coquand and Christine Paulin
@CoderPuppy
CoderPuppy / Hurkens.agda
Created July 18, 2022 16:03
Hurkens' paradox in Agda using Impredicativity
module Hurkens where
-- derived from https://github.com/agda/agda/blob/5d30d8e7a25dfced02edefd82699f1f7b6f79316/test/Succeed/Hurkens.agda
-- adapted to use impredicativity instead of --type-in-type
data ⊥ : Set where
{-# NO_UNIVERSE_CHECK #-}
record Impred₁ (A : Set₂) (B : A → Set₁) : Set₁ where
field at : (a : A) → B a
@CoderPuppy
CoderPuppy / Hemem.hs
Created April 18, 2021 02:14
Writing Hindley-Milner from memory for the first time
{-# OPTIONS_GHC -Wno-tabs #-}
{-# LANGUAGE ImportQualifiedPost, LambdaCase, BlockArguments #-}
module Hemem where
-- roughly Hindley-Milner type inference
-- my first implementation
-- in 1½ hours with no reference
-- just things I pulled from memory (of reading articles about HM)
-- missing an occurs check
@CoderPuppy
CoderPuppy / inv-test.lua
Last active February 5, 2021 04:17
ComputerCraft Inventory System
local I = dofile 'cc/mining/inventory.lua'
xpcall(function()
dofile 'cc/mining/inventory-ui.lua' (I)
end, function(err)
if err == 'Terminated' then return end
sleep(3)
term.setTextColor(colors.red)
term.setBackgroundColor(colors.black)
term.clear()
term.setCursorPos(1, 1)
@CoderPuppy
CoderPuppy / tunneler.lua
Last active January 31, 2021 18:03
ComputerCraft Tunneler
local fill_i
local fill_left = 0
local function place_fill(f)
if fill_left <= 0 then
local is = {}
for i = 1, 16 do
local d = turtle.getItemDetail(i)
if d then
is[d.name] = is[d.name] or i
end
@CoderPuppy
CoderPuppy / guix-idris.scm
Created October 2, 2020 15:29
Guix packages for Idris 2, bootstrapping all the way
(use-modules
(guix profiles)
(gnu packages idris)
(guix packages)
(guix git-download)
(guix download)
(guix build-system gnu)
((guix licenses) #:prefix license:)
(gnu packages multiprecision)
(gnu packages llvm)
@CoderPuppy
CoderPuppy / big-spruce.lua
Last active January 29, 2021 23:29
[CC] Big Spruce Tree Farm
local function refuel(n)
local sel = turtle.getSelectedSlot()
local slot = 1
while turtle.getFuelLevel() < n do
if slot > 16 then
error 'no fuel'
end
turtle.select(slot)
if not turtle.refuel(1) then
slot = slot + 1
@CoderPuppy
CoderPuppy / LamCo2.hs
Created January 30, 2019 15:49
Applying "Functional Derivation of a Virtual Machine for Delimited Continuations" to an evaluator with multi-prompt delimited continuations
{-# OPTIONS_GHC -Wno-tabs #-}
module LamCo2 where
import Numeric.Natural
data Term
= Var Int
| Lam Term
| App Term Term