I'm trying use Haskell Diagrams to make my own function which places two diagrams horizontally/vertically adjacent to one another (like ||| or ===) but with a space between them. If I try to do like this, I get error: Illegal equational constraint V a ~ R2
emptyBlock = rect (3) (1) # fc white # lc white
(||||) :: (Juxtaposable a, V a ~ R2, Semigroup a) => a -> a -> a
(||||) = (|||) emptyBlock (|||)
(====) :: (Juxtaposable a, V a ~ R2, Semigroup a) => a -> a -> a
(====) = (===) emptyBlock (===)
I would be very thankful if anyone could help me to fix this problem.
There are several problems.
GADTs
orTypeFamilies
language extension to use type equality constraints (the ones that mention~
).Your syntax isn't quite right:
(===) emptyBlock (===)
is attempting to put the two "diagrams"emptyBlock
and(===)
above each other. Since(===)
isn't a diagram, but rather a function that forms diagrams, this isn't going to fly. You should writeinstead.
You claim that
(||||)
and(====)
work for any juxtaposable diagrams, but its implementation includes a white rectangle, which means it has to be something that can be styled, has trails, and can be transformed. Change the type signature lines as follows:(Or, possibly, omit it entirely if you plan to disable the monomorphism restriction.)
emptyBlock
a type signature, and it is typeclass polymorphic, so the monomorphism restriction kicks in. Give it a type signature, or turn off the monomorphism restriction by enabling theNoMonomorphismRestriction
language extension.Implementing these four changes results in the following complete file:
However, this still leaves a few things to be desired:
You can fix both of these things using
strutX
andstrutY
instead ofemptyBlock
. This will also be more general: you won't need to include the odd-seeming stylable/transformable constraints. An example of this approach would be: