grace icon indicating copy to clipboard operation
grace copied to clipboard

Total type prettyprinting

Open luna-spirito opened this issue 2 years ago • 2 comments

Current Pretty (Type s) implementation contains possibly infinite path ... -> prettyQuantifiedType -> prettyFunctionType -> prettyApplicationType -> prettyPrimitiveType -> prettyQuantifiedType -> ....

While the current implementation never runs into this infinite recursion, adding new types while forgetting to update prettyQuantifiedType yields no warnings and causes run-time infinite recursion that is hard to debug.

This PR removes multiple functions with error-prone wildcard matches and adds a single function that matches on all possibilities to generate a render tree, which is then automatically reduced and prettyprinted.

luna-spirito avatar Aug 21 '23 13:08 luna-spirito

Yeah, I'm aware of the potential for infinite recursion but I'm sort of partial (pun intended) to the current implementation and I explain why a bit in this post: https://www.haskellforall.com/2020/11/pretty-print-syntax-trees-with-this-one.html

Gabriella439 avatar Aug 25 '23 01:08 Gabriella439

Totally (pun intended) agree that the current implementations looks cleaner. But I proposed this PR due to the "ready-to-fork" nature of the language: I'm a compilation-error-driven developer, and I'm afraid that many people who are new to the codebase, just like me, will forget to add the type prettyprinting and then wiill have to start up the debugger and step through everything in order to find the infinite loop.

As an alternative, maybe I could make a PR that introduces "consumed" Bool flag to all the functions to detect the infinite loop and at least throw impure error exception? Or some other approach?

luna-spirito avatar Aug 25 '23 09:08 luna-spirito