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