Plurrrr

Tue 01 Nov 2022

Data validation in Haskell

Haskell is one of my favorite programming languages, and one of the reasons I like it so much is how nicely it supports modeling string-like data with newtypes when doing web programming. Much of web development involves dealing with strings (idk why exactly but I imagine mostly because JavaScript and the fact that most web communication protocols use strings as primitives), but not all strings are created equal! Strings can be emails, or addresses, or routing numbers, or can be a range of possible enums, and just using type String to capture all of the variance is a poor data model: it doesn’t have the granularity needed to distinguish between different use cases.

This is where using newtypes can help. Using newtypes (and their associated smart constructors) to model string-like data is a nice approach for adding granularity to strings to help differentiate string-like types from each other. Furthermore, the enhanced data modeling provided by newtypes can be extended (via aeson) all the way to JSON parsing, which makes it possible to write a JSON API client in Haskell that provides a type-safe parsing experience with ergonomic errors and a high degree of confidence with respect to data validation. It’s even easy to write tests! To explain more about what I mean, let’s dive into an example of some data modeling I’m doing for an upcoming project that takes advantage of newtypes smart constructors, and custom JSON parsing with aeson.

Source: Data validation in Haskell with newtypes, smart constructors, and aeson, an article by Dylan Martin.

Python 3.11 micro-benchmark

When I first heard the faster CPython initiative, I was intrigued to find out, how does it translate to small application performance across various versions since a lot of critical components are already in C like Postgresql driver. The faster CPython presentation clear states, the performance boost is only guaranteed for pure python code and not C-extensions.

In this post, I’ll share my benchmark results on a couple of hand picked snippets. There is a PyPI package data, do some transformation or do some network operations or file operations. How does that perform against different Python versions.

Source: Python 3.11 micro-benchmark.