diagrams / diagrams-lib

Diagrams standard library
https://diagrams.github.io/
Other
138 stars 62 forks source link

The `bg` function requires the `Any` query monoid #318

Closed AlexKnauth closed 6 years ago

AlexKnauth commented 6 years ago

Currently the bg function has the type:

(TypeableFloat n, Renderable (Path V2 n) b) =>
Colour Double -> QDiagram b V2 n Any -> QDiagram b V2 n Any

With the Any monoid fixed. Is there a reason for this? https://github.com/diagrams/diagrams-lib/blob/1f863bf987c8babff112fb235ba28aa31d4c667a/src/Diagrams/TwoD/Combinators.hs#L261-L264

Why can't it be polymorphic in all monoids:

bg' :: (TypeableFloat n, Renderable (Path V2 n) b, Monoid' q) => 
       Colour Double -> QDiagram b V2 n q -> QDiagram b V2 n q
bg' c d = d <> boundingRect d # lwO 0 # fc c # value mempty

The # value mempty is the only added code, and it makes sense to me that the "background" of a diagram should produce mempty for the query value. In particular it should make it so that adding # bg color to a diagram doesn't change the results of queries.