Skip to content

Instantly share code, notes, and snippets.

View crdrost's full-sized avatar

CR Drost crdrost

View GitHub Profile
@crdrost
crdrost / hughes-lists.hs
Created July 13, 2018 19:51
Paper of the day: Hughes Lists
-- paper of the day
-- RJM Hughes, A Novel Representation of Lists and its Application to the Function "Reverse"
-- Information Processing Letters 22:141-144 (1986)
-- https://www.cs.tufts.edu/~nr/cs257/archive/john-hughes/lists.pdf
{-# LANGUAGE DeriveFunctor, DeriveFoldable #-}
module HughesLists where
import Data.Monoid
import Data.Foldable
@crdrost
crdrost / README.md
Last active June 10, 2019 20:32
best rational approximations, incrementally

Calculating best rational approximations incrementally

So best rational approximations come from a continued fraction expansion.

A continued fraction expansion comes from the loop,

function* continuedFraction(x: number): Iterable<number> {
  let n = Math.floor(x)
  yield n
@crdrost
crdrost / basics.md
Created August 1, 2019 16:49
Buda notation

The Privilege of Buda united Hungary and Poland, similarly Buda notation unites Hungarian notation (name variables after their type) with Polish notation (use prefixes of known arity to process things without ambiguity).

Operators: the character ' is reserved for functions, and it accepts two types. Following Joel Spolsky the first type is the output and the second type is the input. So 'yx is a segment of a variable name identifying a function variable of type x -> y.

Leading ' characters are inferred at the beginning of the variable name to make the name make sense.

@crdrost
crdrost / musical-notes-description.md
Last active September 4, 2019 22:15
Good numbers of musical notes

I wanted to know what sorts of equal temperament systems were objectively better than others as 12-TET occupies a very distinctive place in music theory right now.

More description to come later.

Feel free to use/modify the below code under the MPLv2 license.

package parse_argo
import (
"io"
"regexp"
"github.com/go-logfmt/logfmt"
"github.com/msoap/byline"
)
@crdrost
crdrost / Readme.md
Created November 27, 2024 19:33
Sum Types in Other Languages

Just a quick blog about how to represent discriminated unions, also called sum types.

What are they?

A union type allows you to store one of N distinct types in the same variable. What makes it discriminated is that, if the types overlap, you should still be able to tell the cases apart.

So for example maybe we want to define a variable context which might store either a FooContext or a BarContext or a BazContext, all of which are nullable types (for other reasons in our code, let's say). When we store a null FooContext in context, we want context to still be able to tell us that it's holding a FooContext, just the null version of that. That makes it a discriminated union.

These are called "sum types" because this lack of overlap means that if there were two valid values for FooContext (the null one and some global one, say), three for BarContext, and four for BazContext, the number of valid values for context would be 2+3+4. It could have been less than this if they were allowed to "overlap