Skip to content

Instantly share code, notes, and snippets.

@stetrevor
stetrevor / haskell-difference-list.md
Last active September 6, 2023 08:19
Haskell Difference List

I was reading a book called Algebra of Programming, when I came upon an optimazation about a list concatentation operations.

It says that the (++) operator takes quardraic time causing the program to be slow, and gives an optimization that I couldn't quite understand.

A little more research on this topic leads me to the difference list, stating that left association makes the (++) operations are slow.

But it didn't quite explain why or offered any solution.

Curosity got the best of me, so I decided to experiment. I first created a function to generate positive integer list using concatation.

...
export default {
created() {
if (this.$workbox) {
this.$workbox.addEventListener("waiting", () => {
this.showUpgradeUI = true;
});
}
},
import wb from "./registerServiceWorker";
Vue.prototype.$workbox = wb;
import { Workbox } from "workbox-window";
let wb;
if ("serviceWorker" in navigator) {
wb = new Workbox(`${process.env.BASE_URL}service-worker.js`);
wb.addEventListener("controlling", () => {
window.location.reload();
});
<link rel="manifest" href="<%= BASE_URL %>manifest.json">
const { GenerateSW } = require("workbox-webpack-plugin");
module.exports = {
publicPath: process.env.NODE_ENV === "development" ? "/vuejs-pwa/" : "",
configureWebpack: {
plugins: [new GenerateSW()]
}
};