On Saturday afternoon, I decided to learn more about OCaml since it has long been on my list of "interesting languages I should look into sometime". The wikipedia page had a link to the F# project. It is to OCaml as Boo is to Python: a .Net implementation that mutated the language by enhancing some features, smoothing out some rough edges, and, last and least, taking on new restrictions/limitations due to the platform. Here's a nice table. I've read recreationally about some other functional languages like Lisp, Scheme, Haskell, but I must say that OCaml/F# appeals to me the most at this point. Part of the reason may be because of the down-to-earth, clearly written tutorial I skimmed through. Honestly, my comprehension level reminded me of when I learned Perl. When you start out at ground zero, the code looks like so much gibberish (Python would be an example of code that at least looks more welcoming to beginners), but with each little bit you learn the code makes more and more sense. Haskell gave me the same impression, but on the other hand I still can't read Haskell code as fluently as I can read OCaml now.
Some of the specifics I like:
- OCaml is fundamentally functional, but it has perfectly adequate support for imperative and object-oriented styles if the need arises. F# has different ways of doing objects than OCaml, but for the sake of CLR interoperability this could be a hybrid bug/feature. OCaml is multi-paradigm to a pleasing degree. Lazy evaluation can be turned on at will.
- An impressive list of language primitives, and unlike some other languages the primitives are REAL unboxed primitives, not object wrappers. Tuples, lists of course, records, discriminated unions, even references for those cases in which you feel you must have a true variable to store an intermediate result. The syntax doesn't make you want to choke yourself, either.
- It has good roots and history. OCaml is not just a project that outgrew its original boundaries; it was carefully architected upon solid theoretical work.
- Static typing without explicit variable type declarations. I like to think of it as adding program efficiency and safety without even trying. Of course, this can only go so far before the programmer needs to intervene to prevent the compiler from guessing wrong, but it's still a marvel. Something about me just gets queasy at the idea of a variable containing a variety of possible things at runtime, or morphing into something else accidentally. OCaml does offer a 'generic' type, by the way, and since its operators can handle all data types, functions with generic type parameters just work without having to write separate code paths per type. Its templating ability is par excellence.
- It's not Ruby. I have an irrational animosity toward anything that even hints of being the latest pasture for sheeple, even if the category is "languages with functional features and dynamic (meaning the type is not set at compile time) typing". I hate the concept of a herd controlling my thoughts, with or without my consent.
Haha... I use that quote, and try to paraphrase Palpatine as often and as surreptitiously as possible in my conversation. Peace
ReplyDeleteArché