Skip to content

Pretty type-class compatibility with ansi-wl-pprint #102

@ony

Description

@ony

It looks like there is no way to annotate with colors when implement Pretty instance since its functions polymorphic on annotation type.

Consider

newtype Amount = Amount Int
instance Pretty Amount where
    pretty (Amount n)
        | n < 0 = annotate (colorDull Red) $ pretty n
        | otherwise = pretty n

Is there any suggestions about migrating in this case?

Suggestion

MultiParamTypeClasses

class Pretty a ann where
    pretty :: a -> Doc ann

This seems to model pretty better since it is indexed by both what we render and which annotations we want to collect.

In case of simple types we can keep ann unrestricted and allow rendering for any annotation type.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions