OCaml Module 11
Advanced types interview questions
2 interview questions on advanced types from OCaml: short warm-ups, then what each harder question tests, the first step of a good answer and its follow-ups.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher to mid
What is a GADT, and how does it differ from a plain variant?
Answered in the lesson Generalised algebraic data types (GADTs)
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Mid to senior
You are modelling a filter clause with And, Or, Not and primitives such as Equals and Contains. Every primitive takes string arguments and every clause evaluates to a bool. A teammate wants a GADT; another argues for a plain variant. How would you decide?
- What it tests
- Picking the shape by what the compiler would refine with the index, rather than by habit; weighing the extra text and messages against the compile-time guarantees.
- First step
- List what the GADT index would carry here: with every primitive taking a string and every clause evaluating to bool, the index would be bool for every constructor. The GADT would then rule out no case the plain variant would allow, so the extra apparatus pays for nothing.
- Follow-ups
-
- What would change if primitives also took ints or booleans, and the evaluator should return the column's type?
- How would you write a well-formedness check on each variant, and what does the plain variant make easier?
- When would you surface an error to the user versus letting the type system catch it?
From the lesson Generalised algebraic data types (GADTs)
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.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
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 5 minutes