What are row types? Are they algebraic data types?

First of all, let’s ensure that we use terminology that is consistent with the OCaml type system and corresponding white papers. There is no such thing as “row type”† in the type system of OCaml, however, it has “row polymorphism” and we will discuss it below0. Row polymorphism is a form of polymorphism. OCaml provides … Read more

Algorithm for type checking ML-like pattern matching?

Here’s a sketch of an algorithm. It’s also the basis of Lennart Augustsson’s celebrated technique for compiling pattern matching efficiently. (The paper is in that incredible FPCA proceedings (LNCS 201) with oh so many hits.) The idea is to reconstruct an exhaustive, non-redundant analysis by repeatedly splitting the most general pattern into constructor cases. In … Read more

If SML.NET had functors why can’t F#?

There’s no fundamental limitation of .NET that stops functors from being implemented in F#. True, they can’t be represented directly in .NET metadata, but neither can other F# language features like union types. Compilers for languages with functors (e.g., Standard ML, OCaml) have a pass called defunctorize; it works just like C++ template expansion, in … Read more

Using regular expressions to validate a numeric range

Using regular expressions to validate a numeric range To be clear: When a simple if statement will suffice if(num < -2055 || num > 2055) { throw new IllegalArgumentException(“num (” + num + “) must be between -2055 and 2055”); } using regular expressions for validating numeric ranges is not recommended. In addition, since regular … Read more