Skip to content

Instantly share code, notes, and snippets.

View steshaw's full-sized avatar
👨‍💻
Loves programming languages

Steven Shaw steshaw

👨‍💻
Loves programming languages
View GitHub Profile
#!/usr/bin/env bash
set -euo pipefail
# Always use the by-id aliases for devices, otherwise ZFS can choke on imports.
DISK=${DISK:-/dev/disk/by-id/nvme-Samsung_SSD_970_EVO_Plus_500GB_S4EVNF0M531397T}
EFI=${EFI:-true}
function Usage() {
echo "usage: $0 install|revert" >&2
@steshaw
steshaw / fpmax.scala
Created September 26, 2023 06:05 — forked from jdegoes/fpmax.scala
FP to the Max — Code Examples
package fpmax
import scala.util.Try
import scala.io.StdIn.readLine
object App0 {
def main: Unit = {
println("What is your name?")
val name = readLine()
#
# On macOS ARM64, compile using:
#
# $ arch -x86_64 clang main.s
#
# Run with:
#
# $ ./a.out
#
# Inspect exit code:
@steshaw
steshaw / answer.nix
Last active July 17, 2023 08:36
The answer to life, the universe, and everything
let x = 32; in (let x = 10; in x) + x
.globl main
main:
movq $10, %rax
addq $32, %rax
retq
def parity(p):
return sum(
1
for (x, px) in enumerate(p)
for (y, py) in enumerate(p)
if x < y and px > py
) % 2 == 0
print(parity([1,2,3]))
print(parity([1,2,3,4]))
@steshaw
steshaw / apld-finkel.pdf
Last active June 30, 2023 10:11
Advanced Programming Language Design by Raphael A. Finkel (for personal use only)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#! /usr/bin/env nix-shell
#! nix-shell -p "haskellPackages.ghcWithPackages (pkgs: with pkgs; [http-conduit http-types bytestring])" -i runhaskell
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/293a28df6d7ff3dec1e61e37cc4ee6e6c0fb0847.tar.gz
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE OverloadedStrings #-}
import Control.Monad (forM)
import Data.ByteString qualified as B
/-
Following along with the Logical Foundations book, available at
https://softwarefoundations.cis.upenn.edu/lf-current/Basics.html
-/
inductive Day : Type :=
| monday
| tuesday
| wednesday
| thursday
// https://github.com/namin/unsound/blob/master/unsound.scala
object unsound {
trait LowerBound[T] {
type M >: T;
}
trait UpperBound[U] {
type M <: U;
}
def coerce[T,U](t : T) : U = {
def upcast(ub : LowerBound[T], t : T) : ub.M = t