Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are parameterized modules/functors available? #98

Open
AeroNotix opened this issue Apr 19, 2021 · 3 comments
Open

Are parameterized modules/functors available? #98

AeroNotix opened this issue Apr 19, 2021 · 3 comments

Comments

@AeroNotix
Copy link

AeroNotix commented Apr 19, 2021

Hi,

I'm trying to make use of parameterized modules / functors and maybe I'm missing something.

module type SomeSig = sig
  val some_function : unit -> unit
end

module type SomeFunctor =
  functor (M : SomeSig) ->
  sig
    val some_function : unit -> unit
  end

module SomeModule : SomeFunctor =
  functor (M : SomeSig) ->
  struct
    let some_function () =
      Io.format "In parameterized module\n" [];
      M.some_function ();
  end

module SomeImpl =
  struct
    let some_function () =
      Io.format "In module implementing SomeSig\n" []
  end

module PMod = SomeModule(SomeImpl)

let main () =
  PMod.some_function ()

When I compile this file with caramel compile *.ml the main function gets compiled into such and there are no compilation errors:

-spec main() -> ok.
main() -> pmod:some_function().

Yet there is no pmod.erl file created, which is how I sort of expected the parameterized modules to be implemented.

@AeroNotix
Copy link
Author

@Ostera @michallepicki sie ma!

Is this something that should be possible? Is this something that needs adding?

@AeroNotix
Copy link
Author

@Ostera where can I look to start learning how to implement this?

@AeroNotix
Copy link
Author

AeroNotix commented May 26, 2021

@xandkar any thoughts on my thinking here?

I was thinking that functors could compile down into "just" another Erlang module with a specific module reference at each call site into the parametrized module being replaced in each instance of a functor.

Can functors be dynamically created at runtime in OCaml? I can't find any documentation which allows for that and cannot seem to make OCaml do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant