caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christophe Garion <tofgarion@runbox.com>
To: Florian Angeletti <octa@polychoron.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Printer for lists in toplevel is different when opening List
Date: Wed, 26 Feb 2020 22:00:55 +0100	[thread overview]
Message-ID: <87v9ntdpx4.fsf@port-garion.isae.fr> (raw)
In-Reply-To: <83871ab5-6859-c684-9457-81fb847147df@polychoron.fr>


On Wed, Feb 26 2020 at 07:36:48 PM, Florian Angeletti <octa@polychoron.fr> wrote:

> The printer for lists is indeed quite sensitive to the exact path of
> the type being printed.
>
> Any manipulation that muddles this path makes the printer revert to
> the generic sum type printer.
>
> Moreover, in the case of `List`, the list type is re-exported as
>
> type |'a| t  =|'a list|  =
> | []
> | (::) of 'a * 'a list
>
> Thus after opening the List module, the toplevel printer sees
>
> 1 :: (2 :: ...)
>
> as
>
> ( 1 :: (2 :: ... : 'a list) : 'a t)
>
> And since t is different that list, it prints the value as
>
> (::)(1, ...)
>
> then starting from the second element, we are back to 'a list and the
> pretty list printer.

OK, thanks for the explanation!

> This means that we can make the situation worse by re-exporting the
> type list as
>
> type |'a| t  =|'a list|  =
> | []
> | (::) of 'a * 'a t
>
> With this definition, we completely confuse the pretty printer for
> lists and are rewarded with:
>
> # [1;2];;
>
> - : int t = (::) (1, (::) (2, []))
>
> If you are interested, I have a small patch that makes the toplevel
> printer identify the list type more reliably:
> https://github.com/ocaml/ocaml/pull/9336 .

Thanks, as Nicolás asked me to open an issue, I will point to your PR.

Best,

Christophe

--
Christophe Garion
GPG: 1982 15B2 64AC 3C34 532D  BF19 6CD6 246C 62DA 5A7F

      reply	other threads:[~2020-02-26 21:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-26 15:30 Christophe Garion
2020-02-26 15:51 ` Nicolás Ojeda Bär
2020-02-26 20:55   ` Christophe Garion
2020-02-26 18:36 ` Florian Angeletti
2020-02-26 21:00   ` Christophe Garion [this message]

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=87v9ntdpx4.fsf@port-garion.isae.fr \
    --to=tofgarion@runbox.com \
    --cc=caml-list@inria.fr \
    --cc=octa@polychoron.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;
as well as URLs for NNTP newsgroup(s).