Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constraint synonym for any valid back end? #108

Open
kindaro opened this issue Oct 6, 2019 · 0 comments
Open

Constraint synonym for any valid back end? #108

kindaro opened this issue Oct 6, 2019 · 0 comments

Comments

@kindaro
Copy link

kindaro commented Oct 6, 2019

So I am learning diagrams for like 2 days. At first it was smooth sailing, but then I decided to
split some diagram definitions out from the Main module. This is when I met type errors like
these:

src/Draw.hs:10:74: error:
    • Couldn't match type ‘V t0’ with ‘V2’
        arising from a use of ‘circle’
      The type variable ‘t0’ is ambiguous
    • In the expression: circle 0.1
      In the expression:
        let r = (sqrt $ fromIntegral $ Graph.size graph :: Double)
        in circle 0.1
      In an equation for ‘node’:
          node
            = let r = (sqrt $ fromIntegral $ Graph.size graph :: Double)
              in circle 0.1
    • Relevant bindings include node :: t0 (bound at src/Draw.hs:10:5)

 

src/Draw.hs:1:1: error:
    solveWanteds: too many iterations (limit = 4)
      Unsolved: WC {wc_simple =
                      [W] $dTrailLike_a27Vn {0}:: TrailLike
                                                    (QDiagram backEnd s0 s1 Any) (CDictCan)
                      [D] _ {2}:: base-4.12.0.0:Data.Typeable.Internal.Typeable
                                    s0 (CDictCan)
                      [D] _ {2}:: RealFloat s0 (CDictCan(psc))
                      [D] _ {1}:: Renderable (Path V2 s0) backEnd (CDictCan(psc))
                      [WD] $dFloating_a27Vo {2}:: Floating s0 (CDictCan)
                      [WD] $dOrd_a27Vp {2}:: Ord s0 (CDictCan)
                      [W] $dMetric_a27Vq {1}:: Metric s0 (CDictCan)
                      [WD] $dFractional_a27Vr {0}:: Fractional s0 (CDictCan)
                      [D] _ {0}:: Num s0 (CDictCan)
                      [D] _ {2}:: Eq s0 (CDictCan)
                      [D] _ {2}:: RealFrac s0 (CDictCan)
                      [D] _ {2}:: Real s0 (CDictCan)
                      [WD] hole{co_a27Vk} {8}:: s0 ~ V2 (CNonCanonical)}
      Set limit with -fconstraint-solver-iterations=n; n=0 for no limit

 

I would probably be struggling with them for a lot longer, have I not found this awesome Stack
Overflow answer
from Daniel @bergey. In short, there is defined a type synonym like this:

type Back b = (V b ~ V2, N b ~ Double,
    Renderable (Path V2 Double) b, Renderable (Text Double) b)

dia2 :: Back b => Diagram b
dia2 = circle 1 # fc blue

I tried it and it actually solves all those type errors!

I understand that this type synonym only covers 2D back ends. But is it not nevertheless awesome?

I propose that type synonyms like this are included in Diagrams.Prelude and written about in the
awesome official manual.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant