In this post I’ll walk through the full implementation of a Virtual DOM in a bit over 200 lines of JavaScript. The result is a full-featured and sufficiently performant virtual DOM library (demos). It’s available on NPM as the smvc package. The main goal is to illustrate the fundamental technique behind tools like React. React, Vue and the Elm language all simplify the creation of interactive web pages by allowing you to describe how you’d like the page to look like, and not worry about...| Marcelo Lazaroni
The Haskell ecosystem has great facilities for searching and navigating package documentation using the browser. haskell-docs-cli allows you to do that much faster without leaving the terminal. Jump to demo The problem Switching focus from the editor to the browser when searching for something on Hoogle or reading a piece of documentation on Hackage is not an ideal workflow. Even having Hoogle as a custom search engine on Chrome and using Vimium to avoid the mouse, the path to the module docu...| Marcelo Lazaroni
TL;DR: There is no Nix-native way of doing that. In this post I describe the process that led to the creation of Nix Package Versions, the tool that provides this functionality. The problem The Nix package manager allows one to easily install and remove different versions of the same package. With nix-shell one can even start a shell environment with a different version of a package that is already installed. This is extremely useful and one of Nix’s killer features. Some time ago I noticed...| Marcelo Lazaroni
In his post about a Telegram bot Joachim Breitner mentions compiling his program into a static binary to have it run in Amazon’s version of Linux without needing to build it inside a container. I was interested in experimenting with Amazon Lambda and having statically linked Haskell programs sounded like a great idea too, so this is a write-up of what it took to get those things working. In the end we will have a Haskell program compiling to a statically linked binary, being built quickly b...| Marcelo Lazaroni
Often I need to download many images from a web page and end up trying and adjusting far too many snippets from Stack Overflow. Here is a snippet that works. Give it two strings to download an image. asyncfunctiondownload(url,name){constres=awaitfetch(url);constblob=awaitres.blob();constblobUrl=URL.createObjectURL(blob);consta=document.createElement("a");a.href=blobUrla.download=name;document.body.appendChild(a);a.click();document.body.removeChild(a);} The browser doesn’t handle downloading...| Marcelo Lazaroni
Imagine you want to write a parser to match any of a set of strings that you know beforehand. In Elm’s standard parsing library you would use Parser.oneOf. Like this: importParserexposing(Parser,oneOf,backtrackable,token,getChompedString)friendName:ParserStringfriendName=oneOf[backtrackable<|token"joe",backtrackable<|token"joey",backtrackable<|token"john"]|>getChompedString Now we can parse the name of our friends. However this parser has a few problems: It is inefficient If the string we a...| Marcelo Lazaroni
In functional programming languages you may find yourself overflowing the stack. This post describes techniques to achieve unbounded recursion without fear of the stack. TL;DR The name of the game is staying tail recursive Enable tail recursion by passing down computed values Stick to one recursive call at a time by passing down a list of recursions to be done If we reach a stack overflow it is because we are not taking advantage of tail recursion. The fix is: use tail recursion. How to do th...| Marcelo Lazaroni
At the current state of web technologies, having our application be unavailable during every upgrade is not acceptable anymore. And if you are updating your application often, which you should, being available during updates is even more important. In this post I will walk you through hot-swapping docker containers without letting any request drop with just one command. Blue-Green deployment is the technique we will use. It involves running your new and old server versions in parallel and hav...| Marcelo Lazaroni
Haskell’s laziness can cause problems with recursive functions if they are not handled properly. In some cases this can be dealt with by using an accumulating parameter. Haskell’s wiki page on the subject does a great job in explaining how that works. Here I register some benchmarks on the wiki’s examples so we can see how much that matters.| lazamar.github.io
In this post we will implement a data compression program in about 150 lines of Haskell.| lazamar.github.io