OCaml MOOC

I just completed weeks 0 and 1 of Introduction to Functional Programming in OCaml and I’m loving it! It took me way too long to figure out how scoping works in the “Definitions” section, but I think I finally got it. I watched the video over and over a bunch of times and kept trying examples in the REPL. It’s not C-like at all, but I guess it kind of makes sense.

The course is entirely in the browser, so there’s no need to install OCaml locally.

screen shot of FUN platform with inline OCaml

That’s great for the course instructors, who get to avoid the inevitable questions from the students with, er, proprietary operating systems. But it’s no way to live. I want to write code in my editor of choice and run it locally, so I went ahead and installed OCaml.

On this Ubuntu 18.04 machine, I installed OPAM, the OCaml Package Manager (like CPAN for Perl or cargo for Rust), with

sudo apt install opam

This installed OCaml

$ ocaml --version
The OCaml toplevel, version 4.05.0

$ opam --version
1.2.2

but also installed the package manager in case I want to install any other modules as the course goes on.

Now, what’s that “toplevel” all about in that ocaml version line? In week 0, they explain that toplevel is what they call the REPL (read evaluate print loop) in OCaml. Now that we’ve installed it, we can invoke it with just “ocaml” on the command line. However, it doesn’t have readline support (boo!), so we need to invoke it with rlwrap

$ rlwrap ocaml
		OCaml version 4.05.0

# let foo = "Hello, World!";;
val foo : string = "Hello, World!"

That’s enough for now. I’m sure I’ll be moving to my editor soon, but this is already better than working in the browser.

Advertisements
OCaml MOOC

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s