Comments (1)
On the surface, and without any detailed knowledge of the prettyprinter internals, it seems like an identity instance is trivial to add:
instance Pretty (Doc ann) where pretty = id
Unfortunately it's not quite this easy:
ghci> instance Pretty (Doc ann) where pretty = id
<interactive>:4:42: error:
• Couldn't match type ‘ann1’ with ‘ann’
Expected: Doc ann -> Doc ann1
Actual: Doc ann -> Doc ann
‘ann1’ is a rigid type variable bound by
the type signature for:
pretty :: forall ann1. Doc ann -> Doc ann1
at <interactive>:4:33-38
‘ann’ is a rigid type variable bound by
the instance declaration
at <interactive>:4:10-25
• In the expression: id
In an equation for ‘pretty’: pretty = id
In the instance declaration for ‘Pretty (Doc ann)’
• Relevant bindings include
pretty :: Doc ann -> Doc ann1 (bound at <interactive>:4:33)
Is there a trick to make the annotation type of the input and output Doc
s match up?
Looking through the history, I noticed that there was a general instance before, but one that removed all annotations:
instance Pretty (Doc ann) where pretty = unAnnotateThis was surprising to me, since it wasn't clear why using
pretty
should remove pre-existing annotations.
The relevant commit seems to be b653d59. This was long before my involvement in this project, but it seems that the removal was motivated by the (performance) pitfall documented in the instance haddocks:
since this un-annotates its argument, nesting it means multiple, potentially costly, traversals over the 'Doc'.
Maybe @quchen can provide more context.
To get back to the instance, I wonder how to best avoid the unAnnotate
pass. Maybe we could consider having an instance for Doc
s that cannot contain annotations, e.g.
instance Pretty (Doc Void) where
pretty = unsafeCoerce
(dhall
uses a similar trick.)
from prettyprinter.
Related Issues (20)
- Renderers based on `text-builder-linear` HOT 2
- Rendering of `SLine` could be optimized
- `unsafeTextWithoutNewlines` might be slower than necessary HOT 1
- Use `Color`, `Intensity` etc. from `ansi-terminal` HOT 3
- Use `Foldable` instead of list?
- Define `vsepHard`
- Confusion about how an HTML backend should be implemented HOT 3
- Generalize hsep, etc. to any Foldable, not just list
- How to wrap on any space? HOT 1
- BUG pretty not working on Windows: "invalid character" HOT 4
- Pretty instances for 4-tuples etc.
- Move grouping in `encloseSep`
- `prettyprinter-compat-ansi-wl-pprint ` is not quite a drop-in replacement as claimed HOT 1
- Support using tabs instead of spaces for indentation HOT 2
- Support types in Foreign module
- Pretty-print floats and doubles efficiently.
- prettyprinter-ansi-terminal is not compatible with -text option HOT 1
- Example code is broken HOT 1
- Rename directory named `aux`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prettyprinter.