简体   繁体   中英

Ocaml unbound module

I'm learning Ocaml language but i have a problem with my modules when i want to compile them. So, I have a module with the name Door and an other one with the name Case. Into each one, i have a type paramater with the other module :

Door.mli
type t = bool -> Case.u -> t

Case.mli
type u = bool -> Door.t -> u

When i want to compile, i have this error : File "door.mli", line 14, characters 23-29: Error: Unbound module Case

Have you got an idea ?

Thanks you

You have two mutually recursive modules, which is always tricky. One way to get them to work is to define them in the same file using module rec A ... and B ... .

However, you also have the problem that your types are cyclic. The definition:

type t = bool -> Case.u -> t

is not normally accepted by OCaml either. You can get it to be accepted by specifying -rectypes on the compiler or interpreter command line.

I fear that you'll find these structures to be difficult to work with. The reason they're difficult to define is that they're not usually what you want. You might try starting with more straightforward types if possible.

My advice: get those two types out of door.ml and case.ml , and make Door and Case depend on a common Types module with:

type door = Door of bool -> case -> door
and case = Case of bool -> door -> case

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM