<div dir="ltr">Hi Carter,<div><br></div><div>Yes, I have seen the diagrams project, and in fact am hoping to use them when I actually get to rendering.</div><div><br></div><div>Perhaps, I should have provided more info to try and explain why I am doing this.</div>
<div><br></div><div>I am trying to implement a Gerber file viewer (and maybe editor... we'll see)</div><div><br></div><div><a href="http://www.ucamco.com/Portals/0/Public/The_Gerber_File_Format_Specification.pdf">http://www.ucamco.com/Portals/0/Public/The_Gerber_File_Format_Specification.pdf</a><br>
</div><div><br></div><div>I am using parsec to parse the gerber format and build my gerber data type so that I can make modifications to it, and write it back out.</div><div><br></div><div>I'll take a closer look at diagrams source and see if I can come up with some inspiration.</div>
<div><br></div><div>Thanks,</div><div><br></div><div>Luke</div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jan 13, 2014 at 11:55 AM, Carter Schonwald <span dir="ltr"><<a href="mailto:carter.schonwald@gmail.com" target="_blank">carter.schonwald@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hey Luke,<div>have you seen the diagrams project? <a href="http://projects.haskell.org/diagrams/" target="_blank">http://projects.haskell.org/diagrams/</a></div>
<div>they've struggled through some of the same problems, and they've worked very hard to write a power user friendly expressive DSL lib for that problem domain.</div>

<div>check it out!</div><div>-Carter</div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">On Sun, Jan 12, 2014 at 10:38 PM, Luke Clifton <span dir="ltr"><<a href="mailto:ltclifton@gmail.com" target="_blank">ltclifton@gmail.com</a>></span> wrote:<br>


</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div>Hi,</div><div><br></div><div>I'm quite new to Haskell, and have been loving exploring it. I've always been a huge fan of languages that let me catch errors at compile time, finding dynamic languages like Python a nightmare to work in. I'm finding with Haskell I can take this compile time checking even further than most static languages and it has gotten me rather excited. So I was wondering if there is a Haskell way of solving my problem.</div>



<div><br></div>I'm trying to represent an image made up of a list of strokes. Strokes are either lines, arcs or spots, and can be made using different pen shapes.<div><br></div><div>data Image = Image [Stroke]<br><div>



<br></div><div>data Stroke = Line Point Point PenShape</div><div>    | Arc Point Point Point PenShape</div><div>    | Spot Point PenShape</div><div><br></div><div>data PenShape = Circle Float</div><div>    | Rectangle Float Float</div>



<div>    | ArbitraryPen -- Stuff (not relevant)</div><div><br></div><div>And this is all great and works.</div><div><br></div><div>But now I have a problem. I want to extend this such that Arc strokes are only allowed to have the Circle pen shape, and Lines are only allowed to have the Rectangle or Circle pen shapes.</div>



<div><br></div><div>What is the best way of enforcing this in the type system.</div></div><div><br></div><div>I could make more Strokes like LineCircle, LineRectangle, Arc, PointCircle, PointRectangle, PointArbitrary and get rid of the PenShape type altogether. But this doesn't really feel good to me (and seems like the amount of work I have to do is bigger than it needs to be, especially if I added more basic pen shapes).</div>



<div><br></div><div>I thought about making the different PenShapes different types, using typeclasses and making Stroke an algebraic data type, but then my strokes would be of different types, and I wouldn't be able to have a list of strokes.</div>



<div><br></div><div>I have been looking at DataKinds and GADTs, but I can't quite figure out if they actually help me here at all.</div><div><br></div><div>I'm sure there is a way to do this, I'm just not googling properly.</div>



<div><br></div><div>What I want to write is...</div><div><br></div><div>data Image = Image [Stroke]<br><div><br></div><div>data Stroke = Line Point Point (Circle or Rectangle)</div><div>    | Arc Point Point Point Circle</div>



<div>    | Spot Point PenShape</div><div><br></div><div>data PenShape = Circle Float</div><div>    | Rectangle Float Float</div><div>    | ArbitraryPen -- Stuff (not relevant)</div></div><div><br></div><div>Regards,</div>



<div><br></div><div>Luke</div></div>
<br></div></div>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>