Category: OCaml
-
Structural Versus Physical Comparsions in OCaml
The comparison operators in OCaml are polymorphic. That is, you can use them for various data types. Because OCaml is a typed language, like any other operator, you have to apply them to the same type. E.g., comparing a float to an int will give you a type error. OCaml can perform two types of…
-
Lexical Scoping in OCaml
Like many other modern languages, OCaml uses lexical (or static) scoping. That is, in OCaml, when your function includes a name that calls a variable, in the function, that variable has the value when the function is defined. The opposite is dynamic scoping, in which the variable has the value when the function is called. …
-
Lambda Calculus in OCaml: “fun” and “function”
Lambda is fun! Lambda is certainly fun, but what I mean here is that the λ in lambda calculus is similar to the expression fun in OCaml. Recall that in lambda calculus, we have function expressions and function applications: λx.λy.x+y (*A function expression*) λx.λy.x+y 3 4 (*A function application*) In OCaml, you can express the same…
-
Interfacing OCaml with PostgreSQL
In the last post I talked about building an OCaml project using Dune. In this post I continue with a more complex project. The project interfaces OCaml and PostgreSQL (a database system) with Caqti (a third-party library that provides type-safe abstraction for interfacing with databases). I loosely follow this tutorial, but instead of using Jbuilder…
-
Using Dune to Build an OCaml Project
Dune is a popular OCaml build tool. If you haven’t already, I encourage you to give it a try! Especially if you are building a project that involves more components. See other compiling options here. You can install Dune using OPAM by running (in your system or a particular switch) opam install dune Writing a…
-
Setting Up Merlin in Neovim
My OCaml development environment in Debian has been working well since I set it up. In this post I talk about setting up Merlin in vim and neovim. See this discussion for other well-liked OCaml environment set up. I’ve been using neovim and I like it so I’ll stick with this for now. Setting Up…
-
Currying in Lambda Calculus and OCaml
Currying Recall that in lambda calculus, a function can have more than one input, each preceded by a λ symbol. Another way of thinking about more than one input is currying. Currying a function of two inputs turns that function into a function with one input by passing one of the inputs into it. In other…
-
Setting Up an OCaml Development Environment in Debian
In this post I share how I switched to Debian and set up a development environment for OCaml. As mentioned in this post, I was running NixOS on my machine, but getting it set up comfortably for OCaml seems challenging. Instead of fighting with the OS, I decided to switch to Debian because I love…
-
More on Imperative Merge Sort
I talked about how I wrote imperative merge sort in OCaml earlier. I have been thinking about improving it because it was not as tidy as I’d like. I learnt a few things in the process: Gain as much information as you can to debug. E.g., it can help to print out intermediate results. I…
-
Imperative and Functional Merge Sort in OCaml
So happy to be back! The last two week I was running around seeing doctors, lab technicians, etc because I had a mysterious lump on my neck. It’s still there, but they figured out that it’s nothing worrisome. I’m so grateful! I’ve always been healthy so this was really shocking. I realized that when I’m…