0

I'm trying to use Irmin with MirageOS, and I'm struggling with all those modules. I took a look at the Canopy sources to try and figure out how Irmin is supposed to be used, and I have this :

let start console clock resolver conduit =
  let (module Context) = Irmin_mirage.context (resolver, conduit) in
  let module Mirage_git_memory = Irmin_mirage.Git.Mem.KV(Context)(Git.Inflate.M) in
  let module Store = Mirage_git_memory(Irmin.Contents.String) in
  [...]

From the start function I can use Store fine, set and read the repo .. How do I pass Store around ? Since all of these types depend on start's parameters, I can't (or don't know how) to define those modules anywhere else, and all my attempts to pass or define Store anywhere else have failed with errors about constructor that would escape their scopes. I did manage to create a store.ml file of my own (like in Canopy), but it's just moving the problem to a new module, I still have no idea how to pass it around.

In canopy they seem to use the Store module exclusively from the start function, which for their purpose is fine, but isn't for what I want to do.

I'm trying to use Irmin, but I assume it's not an Irmin problem, I'm probably just very wrong as to how the module system works in ocaml. When I try to pass it to another function or module I end up with errors like

The signature for this packaged module couldn't be inferred.

Which seems logical, but I don't know how to fix that.

Thanks

glennsl
  • 28,186
  • 12
  • 57
  • 75
Ulrar
  • 895
  • 8
  • 17

1 Answers1

2

First class modules (like let (module Context)) are a bit difficult to handle for the OCaml compiler, and in particular it is often not able to infer their type by itself.

The solution is to add a manual annotation:

let (module Context : Irmin_mirage.CONTEXT) = Irmin_mirage.context (resolver, conduit) in
...
Étienne Millon
  • 3,018
  • 11
  • 27
  • That's easy enough for the context, but what about Store here ? I'm pretty sure I can't do something like ```let func (module Store : Store(Irmin_git.IO)(Git.Inflate.S)) () = ...``` (and I'm even simplifying Store here, it has a lot more parameters than that) – Ulrar Aug 07 '18 at 12:40
  • `Store` is not a first class module here (there are no parens around `module Store`, and it's the output of a functor, not a function), so it should be OK. – Étienne Millon Aug 07 '18 at 14:02
  • Well I can't find how to pass it around, do you have an example ? For now I've worked around it by creating a StoreConfig first class module that contains everything needed to create the actual Store object in another module. It works, but it's annoying to use : I have to pass StoreConfig around everywhere and re-make Store there using it – Ulrar Aug 07 '18 at 14:33