OCaml·OCaml essentials

Modules and functions

Modules group types and functions; functors parameterise modules.

Advanced 10 min read Lesson 4 of 150 Challenge included
What you will be able to do
  • Define with module M = struct ... end.
  • Use List.map and List.filter.
  • Use dune for builds.

In plain English

Modules group types and functions; functors parameterise modules.

  • Define with module M = struct ... end.
  • Use List.map and List.filter.
  • Use dune for builds.
modules.mlOCAML
module Lessons = struct
  let long values = List.filter (fun n -> n >= 15) values
end

let () = List.iter (Printf.printf "%d ") (Lessons.long [12; 18])
Your turn

Explain it back

Easy

Answer from memory: Which keyword starts a module definition?

TEXT · starter
Your answer…
Check your understanding before moving on.
Knowledge checkQuestion 1

Which keyword starts a module definition?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Small program
Lesson 4 of 150 · 0% of course