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
@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]))
/-
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
import kotlin.sequences.*
fun main() {
val i = iterator {
for (i in 1..10) {
yield(i)
}
yield(99)
}
for (a in i) {
// https://github.com/namin/unsound/blob/master/Unsound9.java
class Unsound9<U,T> {
static class Type<A> {
class Constraint<B extends A> extends Type<B> {}
<B> Constraint<? super B> bad() { return null; }
<B> A coerce(B b) {
return pair(this.<B>bad(), b).value;
}
}
static class DependentSum<T> {
// 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
{ pkgs ? import <nixpkgs> {} }:
(pkgs.buildFHSUserEnv {
name = "python-fhs-shell";
targetPkgs = pkgs: (with pkgs; [
(python3.withPackages(pp: [pp.pip]))
# python39Packages.pip
# python39Packages.virtualenv
#cudaPackages.cudatoolkit_11
]);
runScript = "bash";