Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

OCaml Module 1

Start here: OCaml, opam, dune and the toplevel interview questions

Interview questions on “Start here: OCaml, opam, dune and the toplevel”: warm-ups, then what each harder question tests and how a good answer starts.

9 questions: 3 warm-ups and 6 with model answers · Levels: Fresher to staff

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher to mid

    How do ocamlc and ocamlopt differ?

    Answered in the lesson What OCaml is and where it is used

  2. Fresher to mid

    What is an opam switch, and when would you use a local one?

    Answered in the lesson Install OCaml 5.5.1 with opam and use the REPL

  3. Fresher to mid

    What do dune build, dune exec and dune test do?

    Answered in the lesson Your first dune project and editor setup

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Mid to senior

    A function that sums payment amounts in cents gives correct totals in your native build but wrong, negative totals in the same code compiled with js_of_ocaml for a web page. What is going on, and how would you fix it?

    What it tests
    Knowing that int width depends on the back end (63 bits native, 32 under js_of_ocaml, 31 under wasm_of_ocaml) and choosing a representation that is correct everywhere.
    First step
    Print Sys.int_size and max_int in both builds: 63 bits natively, 32 under js_of_ocaml, so a total above 2,147,483,647 cents, about 21.5 million dollars, wraps around to a negative number in the browser build.
    Follow-ups

    From the lesson What OCaml is and where it is used

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  2. Senior to staff

    Your team must build a command-line tool that parses and checks large configuration files, and someone suggests OCaml. What would you weigh before agreeing, and how would you test the choice cheaply?

    What it tests
    Judging a language choice by its strengths (static types with inference, pattern matching, native speed, a stable toolchain) against team skills, libraries and hiring, with a small time-boxed trial.
    First step
    Name what the tool needs: correct parsing and checking, speed on large files, one binary to ship. Then match OCaml's strengths to those needs and list the risks that are about the team rather than the language.
    Follow-ups

    From the lesson What OCaml is and where it is used

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  3. Mid to senior

    A project builds on your laptop, but the continuous integration job fails with an error about a library version you never installed there. You suspect the job uses a different compiler or switch. How do you find out and fix it?

    What it tests
    Diagnosing which switch and compiler a command really uses (opam switch show, ocaml -version, opam exec) and making builds name their switch or use a local one with locked dependencies.
    First step
    Make the job print what it uses before it builds: opam switch show, ocaml -version, which dune and the version of the library in question. Compare that with the same lines on your laptop.
    Follow-ups

    From the lesson Install OCaml 5.5.1 with opam and use the REPL

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  4. Mid to senior

    A program that uses Unix.pipe crashes with a segmentation fault on one developer's Mac but runs on everyone else's, all with OCaml 5.5.1. How would you narrow it down without guessing?

    What it tests
    Separating code bugs from build and platform causes, reproducing with a minimal program, and using upstream issues and build settings (here the macOS SDK) to find a known trap.
    First step
    Reduce it: build the four-line program that only opens and closes a pipe on the failing Mac. If that crashes too, the cause is the build of OCaml on that machine, not the application's code.
    Follow-ups

    From the lesson Install OCaml 5.5.1 with opam and use the REPL

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  5. Fresher to senior

    Your dune project builds on your laptop, but a teammate's clone of the same commit stops with "Error (warning 26 [unused-var])" and another with "Unbound module Alcotest". Explain each failure and how you would make the project build the same everywhere.

    What it tests
    Knowing dune's profiles (warnings as errors in dev), how stanzas list libraries, and how a project declares its dependencies so every machine installs the same ones.
    First step
    Treat them as two different problems. The warning fails only in the dev profile, so ask which profile each machine uses; the unbound module means the library is missing from the switch or from the stanza, so check both.
    Follow-ups

    From the lesson Your first dune project and editor setup

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  6. Mid to senior

    Code reviews in your OCaml team keep arguing about layout, and two developers' editors reformat each other's code. How would you set up formatting so the arguments stop?

    What it tests
    Using ocamlformat through dune fmt with a committed .ocamlformat that pins the version, and checking formatting in CI with dune fmt's exit status.
    First step
    Make one tool and one version decide: commit a .ocamlformat with version = 0.29.0 at the project root, install that ocamlformat version for everyone, and run dune fmt once in its own commit.
    Follow-ups

    From the lesson Your first dune project and editor setup

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes

All OCaml interview questions · The OCaml track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.