Zulip Chat Archive

Stream: general

Topic: How do you print object that you don't know fully?


lunuy (Feb 08 2025 at 11:10):

I'm studying LEAN4 internals and I want to see the result of Lean.readModuleData function, however, I cannot print it (its type is ModuleData × CompactedRegion) and I cannot derive ToString for it also. In situation like this, how do you print objects? I think implementing printing function for every types is really painful.

Eric Taucher (Feb 08 2025 at 11:24):

lunuy said:

I think implementing printing function for every types is really painful.

In the same boat at present.

What is somewhat helpful but only for the simpler types is using an LLM. Currently find some success with simpler types using Claude and/or Mistral but have not tried all LLMs, e.g.

Create Lean 4 toString and toJson for this type

<type definition>

Also consider using Lean toJson.

One caveat I found with toJson is that a Lean list, ( ['a','b','c'] ) and a Lean array ( #['a','b','c']) will both be converted to a JSON array as there is no JSON list. (JSON syntax)

My lean file for experimenting with toString and toJson.
Had to cut off much of it to meet the posting length. :frown:

example.lean

Kevin Buzzard (Feb 08 2025 at 13:16):

You can enclose code in quadruple backticks to display it properly in spoilers.

Eric Taucher (Feb 08 2025 at 13:28):

Kevin Buzzard said:

You can enclose code in quadruple backticks to display it properly in spoilers.

Did not know that trick for Zulip markdown. To many variations for Markdown and too many forums to learn, oh my!

Yaël Dillies (Feb 08 2025 at 13:34):

That's a standard markdown feature I believe. When you want to enclose something that contains n consecutive backticks, you can use n + 1 consecutive backticks

Ruben Van de Velde (Feb 08 2025 at 14:20):

The use of "standard" when referring to markdown is somewhat risky :)

Mario Carneiro (Feb 11 2025 at 17:50):

@lunuy There are objects of unknown (to lean) type stored inside ModuleData. CompactedRegion you can ignore, it's not really a piece of data itself but rather a handle to the region which stores the ModuleData, and which can be used (unsafely) to deallocate it. You can view arbitrary lean objects using the structure that the garbage collector uses to do its job; this is implemented in the oleandump library, invented precisely for being able to inspect the module data in .olean files


Last updated: May 02 2025 at 03:31 UTC