You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
On Mon, 18 Mar 2019, Heinrich Apfelmus wrote:
Yes please, although that would require figuring out how to deal with compositionality.
In the current Text-based design we could combine the objects with '<br>'.
However, Xhtml would require '<br/>'.
But hm, for lists of numbers you currently use showList, what makes sense, too.
I guess, there should be a DisplayList class
such that for every element type there can be a custom list instance.
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.
On Tue, 19 Mar 2019, Heinrich Apfelmus wrote:
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.
I think the 'showList' design was the answer to the problem, that the
Haskell creators wanted the single [Char] instance to behave differently
from all other list instances.
Is this the case here, too?
My DisplayList approach would be this one:
class DisplayList a where
displayList :: [a] -> Graphic
instance (DisplayList a) => Display [a] where
display = displayList
This would also avoid FlexibleInstances.
Maybe with a default implementation:
class (Display a) => DisplayList a where
displayList :: [a] -> Graphic
displayList = Text.intersperse (Text.pack "<br>") . map display
For graphical objects we might use the stacking with <br> and for numbers
we would use the list notation, i.e. [1,2,3].
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
Activity
HeinrichApfelmus commentedon Mar 18, 2019
Yes please, although that would require figuring out how to deal with compositionality.
amigalemming commentedon Mar 18, 2019
HeinrichApfelmus commentedon Mar 19, 2019
A
DisplayList
class? I would like to stick to the trick that the Haskell Prelude uses, namely that for every type, we also implements ashowList
function that is responsible for showing a list of these things.amigalemming commentedon Mar 19, 2019
HeinrichApfelmus commentedon Mar 19, 2019
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, thedisplayList
function can be added to theDisplay
class with exactly the same code and effect.