Skip to content

Instantly share code, notes, and snippets.

View pqnelson's full-sized avatar

Alex pqnelson

  • Unfold, Inc.
  • Los Angeles, CA
View GitHub Profile
@pqnelson
pqnelson / io.sml
Created September 11, 2023 17:58
IO Monad implemented in SML using Structures
signature MONAD = sig
type 'a m;
val return : 'a -> 'a m;
val bind : 'a m -> ('a -> 'b m) -> 'b m;
end;
signature IO_MONAD = sig
include MONAD;
val exec : 'a m -> 'a;
val getStr : int -> TextIO.vector m;
@pqnelson
pqnelson / prop.sml
Created March 11, 2022 02:49
Basic normalization of propositional logic, in Standard ML
(*
Some basic normal forms for propositional logic.
So far, I have NNF, NENF, DNF, and CNF normalizations.
This is mostly a translation of chapter 2 from John Harrison's _Handbook of Automated Reasoning and Practical Logic_.
*)
datatype 'a Formula = True
| False
| Atom of 'a
-- Based on: http://augustss.blogspot.com/2007/10/simpler-easier-in-recent-paper-simply.html
import Data.List (delete, union)
{- HLINT ignore "Eta reduce" -}
-- File mnemonics:
-- env = typing environment
-- vid = variable identifier in Bind or Var
-- br = binder variant (Lambda or Pi)
-- xyzTyp = type of xyz
-- body = body of Lambda or Pi abstraction
@pqnelson
pqnelson / dc-comics.org
Last active April 3, 2022 16:54
Comics associated to each DCAU episode

DCAU Comic Recommendations

Introduction

The DC Universe website is sadly shutting down. They had, on the credits, a link to “associated comic book”. I thought I would compile the list of associated comics for each episode.

If someone wanted to start watching the DC Animated Universe but doesn’t

import Data.Set
type Letter = String
data Term = TTau Integer Letter Relation
| TBox Integer Letter
| TVar Letter
| TSubst Term Letter Term
| TPair Term Term
deriving (Show, Eq)
@pqnelson
pqnelson / _README.md
Last active October 31, 2019 14:45
Project Ideas

This is a growing list of project ideas which may be good for a budding programmer to try. The tasks vary in difficulty and length, but I try to make it language agnostic.

@pqnelson
pqnelson / example.html
Created May 10, 2019 23:03
The Javascript for 538 footnotes
<!-- https://fivethirtyeight.com/features/who-wants-to-be-a-senator-not-these-high-profile-democrats/ -->
<p>Remember that in 2016, <a href="http://crystalball.centerforpolitics.org/crystalball/articles/senate-observations-placing-2018-in-the-context-of-upper-chamber-elections-since-1913/">for the</a> <a href="https://fivethirtyeight.com/features/there-were-no-purple-states-on-tuesday/">first time</a>,<a class="espn-footnote-link espn-footnote-item-expanded" data-footnote-id="1" href="#fn-1" data-footnote-content="<p>Or at least since popular Senate elections began <a href=&quot;https://constitutioncenter.org/interactive-constitution/amendments/amendment-xvii&quot;>after the ratification</a> of the 17th Amendment in 1913.</p>
"><sup id="ss-1">x</sup></a><span class="espn-footnote-item espn-footnote-item-displayed espn-footnote-item-expanded"><span class="espn-footnote-item-inner"><span><p>Or at least since popular Senate elections began <a href="https://constitutioncenter.org/interactive-constitution/amendmen
@pqnelson
pqnelson / filter-uses.py
Created February 25, 2019 15:18
Noweb syntax highlighting
#!/usr/bin/env python
import fileinput
from re import sub
deletemode = False
codemode = False
asmmode = False
breakmode = False
@pqnelson
pqnelson / bdd-rspec.md
Created December 18, 2018 18:47
Random Ruby Notes

Unit testing is best done with BDD in mind.

BDD considers "stories" described in Gherkin (a DSL). Stories have the template:

  • As a (user)
  • In order to (achieve some end)
  • I want to (something to realize that end)

Then we create scenarios which would happen in this story.

@pqnelson
pqnelson / Readme.md
Last active August 25, 2023 12:37
Dispatch Techniques for Interpreters

This was an attempt to see what Visual C++ does to a simple function call, and a simple goto spam type statement. The results are unsurprising (function calls use the call instruction, goto uses the jmp instruction). I produced the assembly by inserting a breakpoint, running the "Debug -> Start Debugging" (F5), then hitting CTRL+ALT+D to view the assembly. It works good enough.

Why?

If you want to implement a virtual machine, for example, which reads in bytecode, your repl function (in, say, C) will look something like: