Skip to content

Instantly share code, notes, and snippets.

View mlms13's full-sized avatar
⚗️

Michael Martin mlms13

⚗️
View GitHub Profile
@mlms13
mlms13 / Work.purs
Created March 22, 2020 19:33
Distribute work evenly among participants
module Main where
import Prelude
import Data.List (List(..), (:), fromFoldable, sortBy, reverse)
data Task = Task String Int
sortTasksByWeightDesc :: List Task -> List Task
sortTasksByWeightDesc = sortBy compareEffort >>> reverse where
@mlms13
mlms13 / Audio.re
Created April 8, 2020 21:27
Reason Web Audio
module AudioDestinationNode = {
type t;
};
module OscillatorNode = {
type t;
[@bs.send]
external connect: (t, AudioDestinationNode.t) => unit = "connect";
};
@mlms13
mlms13 / Recipe.re
Created May 13, 2020 23:17
Brainstorming a structure for storing recipes
module Measurement = {
type t =
| Tsp
| Tbsp
| Cup
| Ounce;
};
module Ingredient = {
type t = {name: string};
@mlms13
mlms13 / Domino.re
Created May 14, 2020 03:51
Combining bs-deriving with Bastet's expected function names
module Face = {
[@deriving (enum, ord, eq)]
type t =
| Blank
| One
| Two
| Three
| Four
| Five
| Six
@mlms13
mlms13 / Promise.js
Last active May 27, 2020 19:57
Promise fails Monad's left identity law
// I've seen some examples of how JS promises fail Functor's composition law
// (by hijacking the `then` field of any JS object), making promises not valid
// functors (and by extension, unlawful monads), but I don't recall seeing a
// concise example of Promise breaking Monad's left identity law (though I'm
// sure this has been demonstrated somewhere before).
//
// The key here is that `return a` doesn't behave as expected when `a` is
// already a promise, due to the auto-collapsing nature of promises.
// Left Identity:
@mlms13
mlms13 / Binary.re
Created August 6, 2025 21:26
Implement basic addition for binary digits
// This is a useless waste of time. I'm not sure why several years ago
// I thought it would be fun to define digits e.g. type t = Zero | One | Two | etc
// and then implement Semiring (or at least addition) for that type.
//
// But it didn't take long before I ran into the need to "carry the one"
// and I wasn't sure how to proceed.
//
// So here, several years later, I've distilled the problem down to base 2,
// which constantly requires "carrying the one" when adding. To solve this
// I just pattern-match on all of the relevant cases.