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 …
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.
Higher order functions and parametric polymorphism
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 …
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 …
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 …
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.
I've always found that analogy strange and misleading …