Syntax Lookup

Enter some language construct you want to know more about.
This is the include keyword.

The include keyword statically "spreads" all public values, types, modules, etc. of a given module into the current module's scope. This is sometimes useful to create supersets / mixins of different modules.

Note that include may make your code more complex and harder to understand when abused. Think twice before using it.

Include module example

ReScriptJS Output
module Message = {
  let greeting = "Hello"
}

module Greeter = {
  include Message
  let greet = name => greeting ++ " " ++ name
}

Similarly, module signatures can also be extended by other module signatures.

Include signature example

ReScriptJS Output
module type Message = {
  let greeting: string
}

module type Greeter = {
  include Message
  let greet: string => string
}

Lastly, you can also extract module types from existing modules using module type of.

Include "module type of" example

ReScriptJS Output
module Message = {
  let greeting = "Hello"
}

module type Greeter = {
  // Includes the type definitions of Message
  include module type of Message
  let greet: string => string
}

References