1
votes

Say A.ml B.ml C.ml D.ml all need to define some same types

type a = ... 
type b = ...

Since I don't want duplicate codes, I put these type definitions in a single file Shared_type.ml and I will do Open Shared_type in A.ml, B.ml ...

Is there a better and elegant way to handle this problem? Also, I feel like there might be something wrong with my underlying design. What are the possible improvements?

1
If you truly have common code that you want to open in every module (I don't believe what you intend is a case though), in 4.02.0 you can use the -open <module> command during compilation. - nlucaroni

1 Answers

1
votes

Yes you should put these declarations in a Shared.mli file containing only declarations, not definitions (you'll give definitions in Shared.ml). This is explained in ยง2.5 modules & seperate compilation

PS I strongly advise you to read entirely the ocaml manual before coding any serious thing in OCaml.