Skip to content

Instantly share code, notes, and snippets.

Avatar
⚗️

Michael Martin-Smucker mlms13

⚗️
View GitHub Profile
@mlms13
mlms13 / Promise.js
Last active May 27, 2020
Promise fails Monad's left identity law
View Promise.js
// 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
Combining bs-deriving with Bastet's expected function names
View Domino.re
module Face = {
[@deriving (enum, ord, eq)]
type t =
| Blank
| One
| Two
| Three
| Four
| Five
| Six
@mlms13
mlms13 / Recipe.re
Created May 13, 2020
Brainstorming a structure for storing recipes
View Recipe.re
module Measurement = {
type t =
| Tsp
| Tbsp
| Cup
| Ounce;
};
module Ingredient = {
type t = {name: string};
@mlms13
mlms13 / Audio.re
Created Apr 8, 2020
Reason Web Audio
View Audio.re
module AudioDestinationNode = {
type t;
};
module OscillatorNode = {
type t;
[@bs.send]
external connect: (t, AudioDestinationNode.t) => unit = "connect";
};
@mlms13
mlms13 / Work.purs
Created Mar 22, 2020
Distribute work evenly among participants
View Work.purs
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 Jan 29, 2020
Reader, I guess
View Reader.re
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 Jan 18, 2020
Structural typing with first-class modules
View Demo.bs.js
// 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 Jan 2, 2020
JS representation of a module when the rei is all at the top level
View ReludeRandom.bs.js
// 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 Dec 21, 2019
Request Weather Data using Relude
View Api.re
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 Dec 17, 2019
Understanding that module example from the PR
View monad.ml
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
You can’t perform that action at this time.