Open Xitian9 opened 11 months ago
There's a question of whether we should require a Monoid
instance for all DropAction
s. This is necessary in order to define a Cell
instance for Formatted
, but doesn't strictly have to be part of the class definition.
class (Monoid (DropAction a)) => Cell a
DropAction
s.instance Cell a => Cell (Maybe a)
and instance (Cell a, Cell b) => Cell (Either a b)
. The fact that we can use mempty
avoids having to introduce a couple of Maybe
s.instance Cell a => Cell (Formatted a)
without any extra hassle.Monoid
instances for all DropAction
s.instance (Monoid (DropAction a), Cell a) => Cell (Formatted a)
Alternatively, we could leave it out of the class definition and just add it in to the instance declaration instance (Monoid (DropAction a), Cell a) => Cell (Formatted a)
.
Monoid
instances for DropAction
s if you don't want to.Monoid
instances, then you can't use Formatted
.instance Cell a => Cell (Maybe a)
and instance (Cell a, Cell b) => Cell (Either a b)
.I think option 1 has the advantage of being conceptually cleaner and with cleaner code, at the cost of a tiny bit of boilerplate for instance definers (which is probably a good idea to do anyway). The fact that option 2 requires UndecidableInstances is a big point against it in my opinion, and I'd strongly recommend the former.
I'll have some free time over the next couple of weeks, if you wanted to make suggestions.
I'm sorry to leave you hanging again. I know exactly what it feels like from your perspective and it is unfair. Basically any change that takes me more than an hour to review is difficult. I can't make any promises there.
This separates the measurement phase from the building phase.
The tests currently fail, but I'm putting this up as draft to solicit feedback on whether this was what you had in mind. The reasons test fail is thatbuildCell $ dropLeft n s
is no longer guaranteed to have the expected width, since it will no longer add padding to get up to the expected width. Correcting this is either a matter of changing the trimming logic elsewhere, or reimplementing the padding logic for now.