Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

instances Display List, Tuples ... #29

Open
amigalemming opened this issue Mar 16, 2019 · 5 comments
Open

instances Display List, Tuples ... #29

amigalemming opened this issue Mar 16, 2019 · 5 comments

Comments

@amigalemming
Copy link
Contributor

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.

@HeinrichApfelmus
Copy link
Owner

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

@amigalemming
Copy link
Contributor Author

amigalemming commented Mar 18, 2019 via email

@HeinrichApfelmus
Copy link
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
Copy link
Contributor Author

amigalemming commented Mar 19, 2019 via email

@HeinrichApfelmus
Copy link
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
Projects
None yet
Development

No branches or pull requests

2 participants