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 [thread overview]
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?
next reply other threads:[~2019-10-11 15:24 UTC|newest]
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 publicly 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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox