Hacker News new | ask | show | jobs
by PeCaN 3709 days ago
It's annoying I guess, but you get over it in a few hours. Interestingly it's only annoying from an ideological standpoint—it's never bothered me when reading or writing code.

Anyway, the reason, along with having separate sets of arithmetic operators, is basically because Ocaml ‘generics’ can't be specialized like C++ templates can. Doing it this way keeps the whole language fully type-inferable.

1 comments

It is actually annoying from a very practical point of view. You cannot, for example, write an algorithm that will work an any sequence type, and then apply it to a list. This is why, for instance, you have List.map and so on
You can, that's precisely why we have functors and for this kind of use cases (abstracting a module over another), they are much nicer than type classes.
As far as I understand, this would only work if standard sequence types were defined inside a functor, which is not the case.
The Ocaml std library is a bit lackluster and people often replace it with something more featureful.

BTW, I think https://github.com/c-cube/sequence is more in closer to the generic iterable datatype you are looking for. You still need to convert to and from the seq type but its pretty close...