Re: [diagrams] Type signature help

7 views
Skip to first unread message

Brent Yorgey

unread,
Apr 26, 2013, 2:57:43 PM4/26/13
to mknig...@gmail.com, diagrams...@googlegroups.com
On Fri, Apr 26, 2013 at 11:41:53AM -0700, mknig...@gmail.com wrote:
> Hi,
>
> I am trying to construct a diagram that requires me to use a specific
> vertex which can be determined with trig but I am trying to use a compass
> method, and I am running into a type error I can't figure out.
>
> In the attached image, I am trying to determine the top point of
> intersection of the two circles, so I connect the two circles by their
> origins, and then copy that segment and rotate it 60 degrees, the endpoint
> of that second segment is the point I am trying to extract.
>
> Problem is when I convert the segment to a path (line 10) in order to
> access the vertex info, the compiler gives me the following error:
>
> vessica.hs:10:39:
> No instance for (HasStyle (Trail R2))
> arising from a use of `joinTrail'
> Possible fix: add an instance declaration for (HasStyle (Trail R2))
> In the first argument of `pathFromTrail', namely `joinTrail'
> In the expression: pathFromTrail joinTrail
> In an equation for `joinPath': joinPath = pathFromTrail joinTrail

Hi Mark,

The error message here is actually a relatively informative one.
HasStyle is a type class for things to which style attributes (like
line color, fill color, etc.) can be applied. The error message is
telling us that Trails are not an instance of HasStyle --- trails are
a purely geometric sequence of segments; they do not possess
attributes like color. The problem is that when you define joinTrail
as

joinTrail = (p2 (0,0) ~~ p2 (1,0)) #lw 0.01 #lc gray

you are constraining it to be something which has attributes---such as
a Diagram but definitely not a Trail. But then you call
'pathFromTrail' on it which expects a Trail.

I have not looked extremely carefully at what you are trying to do but
hopefully it should be relatively simple to move the attributes #lw
0.01 #lc gray to sometime later after you actually stroke the trail or
path to turn it into a Diagram.

> Diagrams is elegant and deep, it's just these type errors that keep
> tripping me up. Also open to advice as to whether that's the best way to
> grab the endpoint of a segment.

Yes, helping people figure out the types is a thorny problem we are
still trying to figure out. Have you taken a look at the Type
Reference in the user manual?

http://projects.haskell.org/diagrams/manual/diagrams-manual.html#type-reference

-Brent
Reply all
Reply to author
Forward
0 new messages