caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] How to shadow nested submodules?
@ 2019-10-11 15:24 Vadim
  2019-10-11 15:40 ` Thierry Martinez
  0 siblings, 1 reply; 3+ messages in thread
From: Vadim @ 2019-10-11 15:24 UTC (permalink / raw)
  To: caml-list

Hello! I'm trying to figure out how shadow/override nested modules in 
OCaml. For example, I want to make ipaddr lib aware of 
ppx_deriving_yojson, so I'm trying something like:


> module type IpaddrS = module type of Ipaddr
> module Ipaddr = struct
>   include (Ipaddr : IpaddrS)
>   let to_yojson t = `String (to_string t)
>   let of_yojson = function
>     | `String s -> begin match of_string s with
>         | Error (`Msg e) -> Error e
>         | Ok r -> Ok r
>       end
>     | _ -> Error "Expected string"
>   module Prefix = struct
>     include Ipaddr.Prefix
>     let to_yojson t = `String (to_string t)
>     let of_yojson = function
>       | `String s -> begin match of_string s with
>                      | Error (`Msg e) -> Error e
>                      | Ok r -> Ok r
>                      end
>       | _ -> Error "Expected string"
>   end
> end
>
> type t = {
>     addr: Ipaddr.t;
>     net: Ipaddr.Prefix.t;
>   } [@@deriving yojson]
but it fails with
> Error: Multiple definition of the module name Prefix.
>        Names must be unique in a given structure or signature.
because `include (Ipaddr : IpaddrS)` has already added it. I can handle 
it with copy and pasting the whole signature of Ipaddr module (`module 
type IpaddrS = sig ...end`) but its too big.
Is there any ways to do it without copypasting?


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-10-11 16:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-11 15:24 [Caml-list] How to shadow nested submodules? Vadim
2019-10-11 15:40 ` Thierry Martinez
2019-10-11 16:09   ` Vadim

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).