Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Ivan Gotovchits <ivg@ieee.org>
To: Francois Pottier <francois.pottier@inria.fr>
Cc: Kenichi Asai <asai@is.ocha.ac.jp>, caml-list@inria.fr
Subject: Re: [Caml-list] automatically resolving open?
Date: Wed, 23 Apr 2025 10:45:46 -0400	[thread overview]
Message-ID: <CALdWJ+xxizBHMz9bz1Qf2K9nb+tQbZj1+DpdU7d6bFRH1iXOsg@mail.gmail.com> (raw)
In-Reply-To: <b1043d81-1eb2-4175-aa64-308f51e7814c@inria.fr>

[-- Attachment #1: Type: text/plain, Size: 1812 bytes --]

An interesting corner case is
```
open struct let map f x = f x end
let () = map (fun _ -> ()) 0
```
since OCaml let's us open anonymous modules. In this case, -dtypedtree
generates an unqualified names. So it would be rather easy to remove all
opens to of the named modules, since OCaml will generate fully qualified
names, e.g., `Texp_ident "Stdlib!.List.map"`, but for anonymous modules, it
would be harder to do.

On Wed, Apr 23, 2025 at 10:32 AM Francois Pottier <francois.pottier@inria.fr>
wrote:

>
> Hello,
>
> Le 23/04/2025 à 16:10, Kenichi Asai a écrit :
> > Would it be possible to transform an OCaml file to the one that does
> > not use open?
>
> I don't know whether it is possible/easy to do this today,
> but it would certainly interesting and useful to have such
> a tool.
>
> I note that the output that you expect cannot always be
> produced, due to name shadowing issues. For example if
> the program is
>
> open List
> module List = struct end
> let test = map (fun x -> x + 1) [1; 2; 3]
>
> then the best output that one can expect is
>
> let map = List.map
> module List = struct end
> let test = map (fun x -> x + 1) [1; 2; 3]
>
> That said (contradicting myself), one can actually obtain
> better output if one is careful to always use absolute paths.
> In this example one could write:
>
> module List = struct end
> let test = Stdlib.List.map (fun x -> x + 1) [1; 2; 3]
>
> which relies on the fact that the name "Stdlib" is not shadowed.
>
> As far as I know there is currently no syntax for absolute
> paths in OCaml (every path is relative, and every name can
> be shadowed). Maybe we should consider adding such a syntax?
>
> --
> François Pottier
> francois.pottier@inria.fr
> https://cambium.inria.fr/~fpottier/
>
>

[-- Attachment #2: Type: text/html, Size: 2446 bytes --]

  parent reply	other threads:[~2025-04-23 14:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-23 14:10 Kenichi Asai
2025-04-23 14:32 ` Francois Pottier
2025-04-23 14:38   ` BOBOT François
2025-04-23 14:45   ` Ivan Gotovchits [this message]
2025-04-23 15:33     ` Jeremy Yallop
2025-04-24  4:33   ` Oleg
2025-04-24  6:39 ` Virgile Prevosto
2025-04-24  9:16   ` Ulysse Gérard
2025-04-24 13:06     ` Kenichi Asai
2025-04-24 13:44       ` Ulysse Gérard

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=CALdWJ+xxizBHMz9bz1Qf2K9nb+tQbZj1+DpdU7d6bFRH1iXOsg@mail.gmail.com \
    --to=ivg@ieee.org \
    --cc=asai@is.ocha.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=francois.pottier@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