Skip to content

instances Display List, Tuples ... #29

Open
@amigalemming

Description

How about Display instances for lists and tuples? This would simplify displaying the results of functions that return multiple results. E.g. the tuple members could be displayed in tiers.

Activity

HeinrichApfelmus

HeinrichApfelmus commented on Mar 18, 2019

@HeinrichApfelmus
Owner

Yes please, although that would require figuring out how to deal with compositionality.

amigalemming

amigalemming commented on Mar 18, 2019

@amigalemming
ContributorAuthor
HeinrichApfelmus

HeinrichApfelmus commented on Mar 19, 2019

@HeinrichApfelmus
Owner

A DisplayList class? I would like to stick to the trick that the Haskell Prelude uses, namely that for every type, we also implements a showList function that is responsible for showing a list of these things.

amigalemming

amigalemming commented on Mar 19, 2019

@amigalemming
ContributorAuthor
HeinrichApfelmus

HeinrichApfelmus commented on Mar 19, 2019

@HeinrichApfelmus
Owner

I think we have the same problem: Some lists should be displayed differently from the default display, just like [Char] should be displayed differently from the default [a]. The only difference is that in our case, it applies to many instances, not just a single one.

We do not have to introduce a DefaultList class, the displayList function can be added to the Display class with exactly the same code and effect.

class Display a where
    display     ::  a  -> Graphic
    displayList :: [a] -> Graphic

    displayList = Text.intersperse (Text.pack "<br>") . map display

instance Display a => Display [a] where
    display = displayList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

      Participants

      @HeinrichApfelmus@amigalemming

      Issue actions

        instances Display List, Tuples ... · Issue #29 · HeinrichApfelmus/hyper-haskell