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

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

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.

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 .

— octachron.


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

  parent reply	other threads:[~2020-02-26 18:37 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 [this message]
2020-02-26 21:00   ` Christophe Garion

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=83871ab5-6859-c684-9457-81fb847147df@polychoron.fr \
    --to=octa@polychoron.fr \
    --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;
as well as URLs for NNTP newsgroup(s).