OCaml with Linux Mint
How to quickly set up OCaml and utop so that it you can use the completion bar without keyboard issues.
I recently decided to revisit my skills and brush up on OCaml, an “ML” style language as I have decided to brush up on all the things I have become a little out of touch with but remember liking a lot at the time!
Following these instructions makes it easy, as simple as:
$ sudo apt install ocaml $ sudo apt install ocaml-libs $ sudo apt install utop
And to install OPAM, the package manager, instructions to be found here in fuller details:
$ sudo add-apt-repository ppa:avsm/ppa $ sudo apt update $ sudo apt install opam
Utop is a much nicer (relative, but for n00bs, yes) command line interface to OCaml, it has a much better user experience and beneath the prompt is “the completion bar”. AN old concept but nicely done here, it shows you what you may type next, and by using the shortcut keys you can slide left and right and select something valid.
Put this in your ~/.lambda-term-inputrc file otherwise you are going to have no end of problems, trust me, the default of Alt+Tab (switch between applications), and Alt-Left, Alt-Right on the completion bar will drive you nuts.
And then put this in it, you can of course read the full documentation and choose other keys but for me this seemed natural:
The final thing I had to do was change the key I used from Alt to Super in the keyboard settings, this meant that I can use Alt+Tab to select the current completion var value. And of course, until I remember to use Super+Tab to switch applications now I will continue to swear under my breath…but, worth it.
Ice ICE baby
I can’t put money on it but I might take the trouble to find out, but the “completion bar” brought back very fond memories of using a Hewlett Packard HP64100A ICE terminal back in my first job ever about 1984 in my embedded microprocessor systems days.
I even wrote a game in Pascal on it, Breakout, as soon as I found the manual section on how to do it! It kinda sucked because you had to “open” and “close” the display RAM and it made the terminal blink. Not fun but hell, it was the 80’s. Of course I could have called it Blastar and gone from there but that wasn’t my destiny on this program run.
Firing up Utop
Having installed it, type
utop and hopefully you will see something like this:
Monad free IO
From here on, it’s down to you I guess! I taught myself OCaml a good five years or so ago when I first started looking at candidate languages for a rewrite of a project. I already knew Haskell quite a bit and OCaml (both being “ML” style languages anyway) is not that different. In one sense it might be easier to grasp in certain ways because it doesn’t purport to be pure like Haskell and it makes IO a lot easier but I leave that as an exercise for the reader as they say.
I think my first sample program will be something graphical…