haskell / haskell/pretty

`render :: Doc ann -> String` considered harmful

Open
#70 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
75
Forks
32
PR merge metrics
No merged PRs in 30d

Description

These functions just throw away the annotations:
https://github.com/haskell/pretty/blob/8242bafa5d1be423f1404e73bc2e83e3022e95f1/src/Text/PrettyPrint/Annotated/HughesPJ.hs#L959-L967
Their type signatures are too general, one can shoot oneself in the foot (esp. when using AI for coding).
Their types should be limited to `Doc Void`, making sure there are no annotations in these documents in the first place. So before their use, the user has to consciously convert `Doc ann -> Doc Void` to be aware of throwing away annotations.
Or these functions should not be there in the first place, so that the user has to convert to a standard unannotated `Doc` first and then render this.

Either would be a breaking change so I don't know how practical that is.
Also, I don't know whether a zero-cost implementation
```
removeAnn :: Doc ann -> Doc Void
removeAnn= coerce
```
is safe.

The alternative to `Void` would be `()` which is safe (use `void`) but not entirely correct, because in `Doc ()` one can still have annotations (albeit only a single kind of annotation).

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.