Hacker News new | ask | show | jobs
by svrb 2050 days ago
This makes it seem like modules are strictly inferior, if you can't assign names to common requirements.
2 comments

I don't see how you come to that conclusion. Assigning a name to a requirement (~ an interface) is the most simple usage of the module. E.g. to define something like IComparable, you could write:

  module type Comparable = sig
    type t
    val compare : t -> t -> int
  end
You can still give a name to the interface. However, interfaces apply to modules, not to types. In Ocaml you'd say "this module implements the Comparable interface" while in an OO languague you'd say "this type is a subtype of Comparable". Sorry for the confusion.
Ah, thanks for the clarification.