How to use ray tracing in Haskell Diagrams

67 views Asked by At

The code

rayTraceP (p2 (0, 0)) (r2 (1, 0)) (circle 1)

causes the error message

 Could not deduce: V a0 ~ V2
      from the context: (Traced a, TrailLike a, Transformable a,
                         V a ~ V2)
        bound by the inferred type for β€˜it’:
                   forall a.
                   (Traced a, TrailLike a, Transformable a, V a ~ V2) =>
                   Maybe (Point (V a) (N a))
        at <interactive>:1:1-44
      The type variable β€˜a0’ is ambiguous

I can't figure out why this happens. It seems that rayTraceP is used similarly in the manual. I use diagrams-cairo-1.4.1 .

1

There are 1 answers

1
Brent Yorgey On

This kind of error is usually caused by ambiguous types during type inference, and can be fixed by adding one or more type signatures. In this case I think the problem is most likely that it can't figure out what type the 'circle 1' call should have. If you show all the code I could give some better advice about where to add a type signature.

See section 5.5 of the user manual for more info: https://diagrams.github.io/doc/manual.html#tips-and-tricks