Skip to content

Instantly share code, notes, and snippets.

View mlms13's full-sized avatar
⚗️

Michael Martin mlms13

⚗️
View GitHub Profile
@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 / 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 / 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 / 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 / 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 / Reader.re
Last active January 29, 2020 22:22
Reader, I guess
let const = (a, _) => a;
let (<<) = (f, g, a) => f(g(a));
module type Type = {type t;};
module Function1 = {
type t('input, 'output) = 'input => 'output;
};
module type Functor = {
@mlms13
mlms13 / Demo.bs.js
Created January 18, 2020 19:59
Structural typing with first-class modules
// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE
'use strict';
var List$Modules = require("./List.bs.js");
var String$Modules = require("./String.bs.js");
var x = List$Modules.contains(String$Modules.Eq, "a", /* :: */[
"b",
/* :: */[
"c",
@mlms13
mlms13 / ReludeRandom.bs.js
Created January 2, 2020 01:34
JS representation of a module when the rei is all at the top level
// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE
'use strict';
var ReludeRandom_Seed = require("./ReludeRandom_Seed.bs.js");
var ReludeRandom_Generator = require("./ReludeRandom_Generator.bs.js");
var ReludeRandom_RandomInt = require("./ReludeRandom_RandomInt.bs.js");
var ReludeRandom_RandomList = require("./ReludeRandom_RandomList.bs.js");
var Seed = {
fromInt: ReludeRandom_Seed.fromInt,
@mlms13
mlms13 / Api.re
Created December 21, 2019 05:08
Request Weather Data using Relude
open Relude.Globals;
let baseUrl = "http://localhost:5050";
// `getForecast` is an IO that will either succeed with decoded
// ForecastData or fail with a Fetch error.
//
// Since IO is inherently lazy, creating this value doesn't actually
// _do_ anything. Instead it needs to be run, which we do inside an
// `UpdateWithIO` return from a `useReducer` branch in our view.
@mlms13
mlms13 / monad.ml
Last active December 17, 2019 17:43
Understanding that module example from the PR
module type Monad =
sig
type 'a t
val map : ('a -> 'b) -> 'a t -> 'b t
val apply : ('a -> 'b) t -> 'a t -> 'b t
val pure : 'a -> 'a t
val bind : 'a t -> ('a -> 'b t) -> 'b t
end
module Option : Monad with type 'a t = 'a option = struct