Force inter-module functor application

Hi,

I’m wondering if it’s possible to make the complier apply a function from another module at compile time.

I have the following two modules:

// Parent.res
module MakeGoodbyer = (Named: Child.Named) => {
  let sayGoodbye = () => Js.log("goodbye " ++ Named.name)
}

module TheNamed = {
  let name = "Alice"
}

module Hellor = Child.MakeHellor(TheNamed)
module Goodbyer = MakeGoodbyer(TheNamed)

Hellor.sayHello()
Goodbyer.sayGoodbye()

and

// Child.res
module type Named = {
  let name: string
}

module MakeHellor = (Named: Named) => {
  let sayHello = () => Js.log("hello " ++ Named.name)
}

Which produces the following output:

import * as Curry from "rescript/lib/es6/curry.js";
import * as Child$Licht from "./Child.mjs";

function MakeGoodbyer(Named) {
  var sayGoodbye = function (param) {
    console.log("goodbye " + Named.name);
    
  };
  return {
          sayGoodbye: sayGoodbye
        };
}

var name = "Alice";

var TheNamed = {
  name: name
};

var Hellor = Child$Licht.MakeHellor(TheNamed);

function sayGoodbye(param) {
  console.log("goodbye Alice");
  
}

var Goodbyer = {
  sayGoodbye: sayGoodbye
};

Curry._1(Hellor.sayHello, undefined);

sayGoodbye(undefined);

export {
  MakeGoodbyer ,
  TheNamed ,
  Hellor ,
  Goodbyer , 
}

As you can see, the application of MakeGoodbyer is optimised away, but MakeHellor is imported and applied at runtime. Is there a way to get the compiler to apply functors from other files at compile time?

Thanks very much :slight_smile:

1 Like

As I know it’s not possible.

Also, I recently had the opposite problem, where I wanted to disable inline optimization

1 Like

There was some experimental flag for cross module(files) optimizations, but it is not enabled (not mature for production quality)

3 Likes

Dang, well thank you both for you help :slight_smile: