Skip to content

Instantly share code, notes, and snippets.

@sgoguen
sgoguen / gist:2298f1a99a910ec79f911c7b1c235571
Created October 5, 2026 23:15
Metamath Loader, Verifier and Explorer/Browser Implemented in F# (LINQPad)
// Metamath loader + proof verifier (F# port of the C# MathEditor example, itself based on mmverify.py).
// Pipeline: text ─tokenize─► tokens ─parse─► RawStatement tree ─load─► Database ─verify─► Verdicts
// Supports $c $v $d $f $e $a $p ${ $}, normal and compressed proofs. Does not support $[ include $].
// ── NOTES: capturing layout & comment metadata ── (1–3: done in Syntax.scan + Layout; 4–6: ideas, not started)
// Principle: keep the core parse lossless-but-dumb; recognize conventions afterwards with active patterns.
// 1. Tokens carry their line number; comments become items too, with their exact text.
// (Offsets/columns and slicing instead of copying are possible later if memory or navigation needs them.)
// 2. Attach comments to statements by position:
// • comment directly before a statement (nothing between) → its doc (e.g. "$( Minor premise $) min $e ...")
@sgoguen
sgoguen / prospero-for-linqpad.fs
Last active May 7, 2025 00:51
Naive F# Port of Prospero
open System
open System.IO
open System.Collections.Generic
// Define a type to hold either a scalar or an image (2D array)
type Value =
| Scalar of float
| Array of float[,] // 2D array representing the image
// Image size (for testing you might want to use a smaller value)
@sgoguen
sgoguen / Result.fsx
Last active March 11, 2025 23:24
Toy Implementation of Maude in F#
module Result
open System
type ResultBuilder() =
member __.Return(x) = Ok x
member __.ReturnFrom(m: Result<_, _>) = m
member __.Bind(m, f) = Result.bind f m
@sgoguen
sgoguen / godelian-auto-constructor.fsx
Last active June 17, 2025 00:24
The Godelian Toolkit - Generating Imperative Programs
////////////////////////////////////////////////////////////////////////
/// The Gödelian Toolkit
////////////////////////////////////////////////////////////////////////
module Nat =
type Nat = bigint
let sqrt (z: bigint) : bigint =
if z < 0I then
invalidArg "z" "Cannot compute the square root of a negative number"
@sgoguen
sgoguen / iso.fsx
Last active February 16, 2025 14:29
Paul Tarau's Iso type in F# from Everything is Everything Paper
(*
This is a port of the Haskell code from Paul Tarau's paper:
Everything Is Everything" Revisited: Shapeshifting Data Types with Isomorphisms and Hylomorphisms
Tarau, Paul. "" Everything Is Everything" Revisited: Shapeshifting Data Types with Isomorphisms and Hylomorphisms." Complex Systems 18.4 (2010): 475.
*)
type Iso<'A, 'B> = Iso of f: ('A -> 'B) * g: ('B -> 'A)
@sgoguen
sgoguen / tree-calculus.maude
Last active January 27, 2025 16:48
Tree Calculus in Maude
--- Tree Calculus
--- The following module defines the core operations of Barry Jay's original tree calculus.
--- For our purposes, we'll represent Δ as the ASCII letter l to represent a leaf.
--- Let's define the syntax of the TRIAGE calculus.
fmod TREE-CALC-SYNTAX is
@sgoguen
sgoguen / tree-calculus.fsx
Created January 14, 2025 17:28
A Gödelian Encoding for Tree Calculus
// The irony of this snippet is that Tree Calculus, unlike Lambda Calculus, is a
// system that was designed to be reflective so one doesn't have to resort to things
// like Gödelian numbering systems or other schemes in order for it to reason about
// its own programs.
// But seeing how I know little to nothing about Tree Calculus, I figured this would be
// an interesting way to explore it.
// Interestingly enough, this snippet was written one month before reading this post:
// https://github.com/barry-jay-personal/blog/blob/main/2025-01-06-diagonal.md
@sgoguen
sgoguen / Unification-Test.fsx
Last active December 11, 2024 05:40
Structurally Recursive Solver for Functions Closed Under Constant Zero, Succ, Double and Full (2^x - 1)
// Nerd sniped by Conor Mc Bride
// https://github.com/pigworker/Samizdat/blob/main/Full.hs
// Agda Proof - https://github.com/pigworker/Samizdat/tree/main/Full
// I really have no idea what I'm doing here.
// The data type Fm is a syntax tree with nodes:
// V x = a variable reference
// Z = zero (a canonical base value)
// D f = double the value represented by 'f'
namespace PolyTypeExample;
using PolyType;
using PolyType.Abstractions;
using PolyType.Examples.Utilities;
public class Examples
{
// public static void
@sgoguen
sgoguen / 01-parameterized-modules.md
Last active August 23, 2024 20:54
Higher Order Functions Considered Unnecessary???

Higher Order Functions Considered Unnecessary??

This is my conversation with my custom GPT. Beyond this point, my questions are in blockquotes, and the GPT's responses are in normal text.

Can you help me explain to my friend how higher-order functions can be replaced with parameterized modules? Here's the rub: I don't want you to do it with OBJ, I want you to show how to do it with parameterized modules in OCaml. FYI - He's an F# programmer, so you don't have to explain things like higher-order functions.

Here's the paper: https://cseweb.ucsd.edu/~goguen/pps/utyop.pdf

Hey Friend,