caml-list - the Caml user's mailing list
 help / color / Atom feed
From: Vadim <vadim@radovel.ru>
To: caml-list@inria.fr
Subject: [Caml-list] How to shadow nested submodules?
Date: Fri, 11 Oct 2019 18:24:33 +0300
Message-ID: <0634cce4-0468-c10e-30c8-8e8e7ec937d7@radovel.ru> (raw)

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?


             reply index

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-11 15:24 Vadim [this message]
2019-10-11 15:40 ` Thierry Martinez
2019-10-11 16:09   ` Vadim

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0634cce4-0468-c10e-30c8-8e8e7ec937d7@radovel.ru \
    --to=vadim@radovel.ru \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

caml-list - the Caml user's mailing list

Archives are clonable:
	git clone --mirror http://inbox.vuxu.org/caml-list
	git clone --mirror https://inbox.ocaml.org/caml-list

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.caml-list


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git