Make Cell lazier to allow more instances#44
Conversation
|
Answering your questions from #37 here.
Within this library, that is indeed the case. You can see from the fact that, aside from in the test suite, no code needed to be changed and it still passes all tests.
I think this actually makes multi-width characters easier, since we don't have to add the padding at each step. The proof will be in the pudding.
It might, but I think we are reasonably safe.
I think they all work as is. Thoughts?
I was thinking that they would be the auto-derived instances: compare the base items, and only if they're equal move on to the left adjustment, and then the right adjustment. That said, this functionality is not used anywhere, so if you object we could leave it out.
I think it's not terrible. The following will basically eliminate the need to consider The two methods means that, whenever you call
Yes, I agree this step would probably not be used in practice. But it can be implemented sensibly, and
Are you proposing partially implementing the |
|
The Monad instance of |
muesli4
left a comment
There was a problem hiding this comment.
The result is much better than what I expected. The actual rendering code does not have to be changed and porting old code is easy.
I'm fine with providing an instance of Cell for CellView.
|
Would you mind discussing the issue about |
|
I've removed the last commit: it looks quite redundant considering #46. |
Previously Cell required being able to drop from the left or right without changing the type of the object. This made it awkward to define instances for which this was not natural. Cell will no longer drop from the left or right immediately. Instead, drop(Left|Right|Both) will record the amount that has been requested to be dropped, and drop it when buildCell is called. Changes to the API require that instance declarations for Cell be changed as follows: 1. instance Cell a where dropLeft = f dropRight = g ... can be changed to instance Cell a where buildCellView = buildCellViewLRHelper buildCell f g ... 2. instance Cell a where dropBoth = f ... can be changed to instance Cell a where buildCellView = buildCellViewBothHelper buildCell f ... 3. instance Cell a where dropLeft = f dropRight = g dropBoth = h ... can be changed to instance Cell a where buildCellView = buildCellViewHelper buildCell buildCell buildCell f g h ... Since dropLeft, dropRight, and dropBoth are no longer class methods of Cell, they may need to be imported explicitly. Code which relies on dropLeft, dropRight, and dropBoth not changing the type of the output may need to be rewritten, possibly by calling buildCell on the result.
|
The pull request has been merged manually. |
Previously Cell required being able to drop from the left or right without changing the type of the object. This made it awkward to define instances for which this was not natural.
Cell will no longer drop from the left or right immediately. Instead, drop(Left|Right|Both) will record the amount that has been requested to be dropped, and drop it when buildCell is called.
Changes to the API require that instance declarations for Cell be changed as follows:
instance Cell a where
dropLeft = f
dropRight = g
...
can be changed to
instance Cell a where
buildCellView = buildCellViewLRHelper buildCell f g
...
instance Cell a where
dropBoth = f
...
can be changed to
instance Cell a where
buildCellView = buildCellViewBothHelper buildCell f
...
instance Cell a where
dropLeft = f
dropRight = g
dropBoth = h
...
can be changed to
instance Cell a where
buildCellView = buildCellViewHelper buildCell buildCell buildCell f g h
...
Since dropLeft, dropRight, and dropBoth are no longer class methods of Cell, they may need to be imported explicitly. Code which relies on dropLeft, dropRight, and dropBoth not changing the type of the output may need to be rewritten, possibly by calling buildCell on the result.