Blog

This is the blog that once lived at blog.baturin.org, but now it's integrated with the main site.

You can subscribe to the Atom feed. You can also subscribe to a feed about OCaml and nothing else.

Embedding and projection in Lua-ML

Last update: 2020-08-28.

Tags: programming, ocaml, lua-ml

One thing I find odd about many interpreter projects is that they are designed as standalone and can't be used as embedded scripting languages. Lua-ML is completely different in that regard: it's designed as an extension language first and offers some unique features for that use case, including a reconfigurable runtime library. You can remove modules from its standard library or replace them with your own implementations. Of course, you can also pass OCaml values to Lua code and take them back in a type-safe manner too. That aspect isn't very obvious or well-documented, so in this post we'll try to uncover it.

Read more

Bundle NPM modules into static JS libraries like it’s 2006

Last update: 2020-08-19.

Tags: js, web, programming

A good thing about browser implementations of JavaScript is compatibility. The NPM ecosystem, however, is infamous for its fragility. As a professional “not a frontend developer” I try to opt out of it as much as possible. Luckily, if you just need a library from NPM, it's easy to package it into an “eternal” blob that will work forever. In this post I'll share my procedure for creating such static JS blobs from NPM modules.

Read more

Migrating the blog to soupault

Last update: 2020-04-05.

Tags: web, self-hosted

I've migrated my blog to soupault. I hope it didn't break too many links or anything else, if you spot a problem, let me know. If you are interested in the details of the migration, read on. However, note that this post is a bit too full of idle musings on blogs, universe, and everything. If a list of pages sorted by date is all you want, read this post instead.

Read more

If you think ReasonML compiles to JS, you are wrong

Last update: 2019-09-05.

Tags: programming, ocaml, js

In this post we'll examine what ReasonML really is and what it compiles to. Everyone coming from the ML community already knows the truth, but in the JS community, this misconception seems surprisingly common. It's not just about giving credit, but about the true potential of the language that is far greater than that of TypeScript or Elm.

Read more

Declarative parse error reporting with Menhir

Last update: 2019-08-24.

Tags: programming, parsing, ocaml

Many parsers for custom formats aren't very user friendly when it comes to error handling. At best you get the line and column where the error is, at worst a “Parse error” message is all you get. Can we do better? With right tools, we definitely can and it's not that hard.

Read more

Extending OCaml programs with Lua (soupault got plugin support)

Last update: 2019-08-10.

Tags: programming, ocaml

Most of the time, when people make extensible programs in typed functional languages, they make a DSL, not least because it's much easier to make a DSL in a language with algebraic types and pattern matching than in one without.
Some use cases really require a general-purpose language though. That's where things get more interesting. Commonly used embeddable interpreters such as Lua, Guile, or Chicken are written in C. It's possible to make OCaml or Haskell bindings for them and such bindings do exist, but that's two high level languages communicating through a low level one.
It would be much better to be able to expose native types to the embedded language in a type-safe and more or less convenient fashion. Here's my take at it.

Read more

Migrating to the new server part 2: moving from Cyrus to Dovecot

Last update: 2018-08-19.

Tags: servers, self-hosted

It's been a while since I published the first part. In case you were worrying how the rest of migration went, well, I ended up with an operational system quickly, even if because I decided not to change the rest of it yet. However, a bug in Cyrus IMAPd made me make perhaps the biggest change in my email setup since its inception. This post chronicles my migration to Dovecot.

Read more

Introduction to OCaml, part 5: exceptions, lists, and structural recursion

Last update: 2018-08-18.

Tags: programming, ocaml

In OCaml, exceptions are not objects, and there are no exception hierarchies. It may look unusual now, but in fact exceptions predate the rise of object oriented languages and it's more in line with original implementations. The advantage is that they are very lightweight.

Read more

Introduction to OCaml, part 4: higher order functions, parametric polymorphism and algebraic data types

Last update: 2018-08-12.

Tags: programming, ocaml

So far we have only worked with functions that take value of a single type known beforehand. However, we have already seen functions whose types were left without explanation, such as let hello _ = print_endline "hello world" that we used to demonstrate the wildcard pattern.
What is its type? If you enter it into the REPL, you will see that it's 'a -> unit. What does the mysterious 'a mean? Simply put, it's a placeholder for any type. Essentially, a variable for types —a type variable.

Read more

Introduction to OCaml, part 3

Last update: 2018-08-08.

Tags: programming, ocaml

This should have been covered earlier, but better late than even later. In this chapter we'll learn about booleans and conditional expressions.

Read more

Introduction to OCaml, part 2

Last update: 2018-08-07.

Tags: programming, ocaml

In the previous chapter we've learnt how to use variables and arithmetic functions. Now it's time to learn how to make our own functions.

Read more

Introduction to OCaml

Last update: 2018-08-06.

Tags: programming, ocaml

This post series started as a response to requests from some friends curious about OCaml. There are quite a few nice books already, but I realized that if I just recommend them any one of those books, it still will leave me with quite a few things to explain in depth, or force me to recommend another just to learn about that part. So I thought I may as well write something that hopefully will allow a person who already knows how to program in some other language get started with writing OCaml programs and continue learning on their own and find their own sources.

Read more

Implementing sets with functions alone

Last update: 2018-04-12.

Tags: programming, ocaml

Implementation of sets using nothing but functions would be one of the first tricks in the “100 Fun Things to Do With Functions and Closures” book if that book existed. It may not be very practical, but it may help people get into the functional mindset. We'll use OCaml for demonstration.

Read more

Hello from a compiler-free x86-64 world

Last update: 2018-04-07.

Tags: programming, assembly

I've stumbled upon two posts where Jessica McKellar demonstrates how to make a C program on Linux without using libc. They were written in 2010 when 32-bit x86 was far from extinct though, and use the old 32-bit ABI—a problem most examples of low level programming on UNIX-like systems suffer from, even if it's not their fault.

Read more

Installing Python package data by relative path

Last update: 2018-04-02.

Tags: programming, python

Package data installation sometimes requires balance between ease of writing installation procecures for it and ease of accessing that data. That's especially apparent when someone who is not a developer wants to be able to edit that data in place. Editing it in place is a bad practice of course, but sometimes that's just what you get. For example, if there are two people of whom one is a developer who wrote code solely from data format specification, and the other understands what the data actually means but has no coding skills.

Read more

Network access and authentication in Cisco Catalyst switches

Last update: 2018-03-31.

Tags: networks, cisco

From the fact that I'm a VyOS maintainer, you can guess that I'm not a fan of Cisco routers, but I'm a big fan of Cisco Catalyst switches. They have never failed me yet, and among all L2 switches they have the least annoying CLI, even though it does have its issues. For L3 switches there may be better alternatives, but for L2, I haven't seen anything better than Catalyst so far.

Read more

MTU calculator makeover

Last update: 2018-03-14.

Tags: projects, web

A new version of encapcalc, an MTU/MSS calculator, is now live at baturin.org/tools/encapcalc, with an improved and sort of mobile friendly UI.

Read more

Migrating to the new server part 1: base system and the web server

Last update: 2018-03-09.

Tags: servers, self-hosted

My current VPS is running CentOS 6, and, frankly, it long started showing its age. Not very surprising if we remember that it was released in 2011. Even with all efforts from EPEL, Remi, and Software Collections maintainers, running new applications on new OS versions is obviously easier than on old verions. That's why I decided to migrate to Fedora, and it was much easier than I thought.

Read more

Anycast routing

Last update: 2018-02-28.

Tags: networking, bgp

It is well known that due to limited practical size of a UDP packet that can be transmitted without fragmentation, the number of DNS root servers is limited to 13 addresses. There are indeed 13 root servers named from A to M (a.root-servers.net, b.root-servers.net and so on). However, if you visit root-servers.org, you can see that most of those servers somehow have dozens and even hundreds locations around the world. How is it possible for one server to have more than one location? The answer is anycast routing.

Read more

Duck typing

Last update: 2018-02-21.

Tags: programming, python, ocaml

So called “duck typing” is often poorly explained and thus often misunderstood. Its name and the adage associated with it (“if it walks like a duck and quacks like a duck, then it is a duck”) don't do it any favors either.

Read more

Yet another dmbaturin’s blog iteration

Last update: 2018-02-20.

Tags: misc, personal

Looks like my blogging cycle is two years in and two years out. Not that I run out of things to write about, it's just that good technical writing is a surprisingly time consuming endeavor. You get to verify every example, check every proof, look up every detail in the standards and so on. The world doesn't need more posts that create more troubles for the reader than they solve.
Still last time what drove me away from blogging was, surprisingly, the tools. So many blogging platforms are horrible, and finding a good one is a challenge.

Read more