I thought to start this off with a book...

ShuShu
2 min read

Free online access —> https://dev.realworldocaml.org/index.html

I love how the book starts off with “programming languages matter”; I agree with this, 100%, as a pdeveloper of cybersecurity products.

I need to find some up-to-date coding practices/resources as I go along; I’m trying everything from the book, but welcome any recommendations at all.

Setting up opam, first OCaml example, and everything in between

Doing everything in Ubuntu.

First things first - you need a C compiler; I went with GCC.

sudo apt install make
sudo apt install gcc

Install opam (OCaml package manager, for Ubuntu) and initialise.

sudo apt install opam
opam init

The install OCaml (I went with 4.14.2) and update the current shell environment,

opam switch create 4.14.2
eval $(opam env)

with some libraries and tools.

opam install core core_bench utop

Not sure why or how it will help at this moment, but followed instructions to create this ~/.ocamlinit file in home directory for now.

#require "core.top";;
#require "ppx_jane";;
open Base;;

I used VS Code as my editor as I’m more familiar with it. If you choose the same, you’d have to set up the OCaml Platform plug-ins (search for it in VS Code “Extension”. You should see a white-camel-on-black-background icon) and an OCaml Language-Server-Protocol (LSP) server (as below).

opam install ocaml-lsp-server

Once done, just start UTop toplevel and try the “OCaml as a Calculator” example (remember the double semicolon (;) at the end of each line!). At this point, I think the ~/.ocamlinit file helped to open Base in my UTop.

utop
3 + 4;;
8 / 3;;
0
Subscribe to my newsletter

Read articles from Shu directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shu
Shu