Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 1965

Does Rescript Still support impl ? (Or, any feature like trait constraints)

$
0
0

Here’s a simpler and less flexible solution that might still be sufficient, and that avoids the complexity of functors:

module type Trait1 = {
  let function1: unit => unit
}

module type Trait2 = {
  let function2: unit => unit
}

module type Trait1And2 = {
  include Trait1
  include Trait2
}

let callFunctions = (module(M: Trait1And2)) => {
  M.function1()
  M.function2()
}

module MyModule = {
  let function1 = _ => Console.log("Method 1 called")
  let function2 = _ => Console.log("Method 2 called")
}

callFunctions(module(MyModule))

Viewing all articles
Browse latest Browse all 1965

Trending Articles