A phantom type might do what you want:<br><br>-- notice the type parameter on point that isn&#39;t used in the type<br>data Point  a  = Cartesian (Cartesian_coord, Cartesian_coord)<br>                         | Spherical (Latitude, Longitude)<br>
<br>-- make some dummy types <br>
data SphericalP<br>
data CartesianP<br><br>--make some constructors that add a restriction to the phantom type<br>-- notice the CartesianP type restriction, this isn&#39;t needed but allows us to restrict our type later if we want<br>mkCartesian :: (Cartesian_coord, Cartesian_coord) -&gt; Point  CartesianP<br>
mkCartesian = Cartesian<br><br>mkSherical :: (Latitude, Longitude) -&gt; Point  SphericalP<br>
mkSherical = Spherical<br><br><br>type Center = Point<br>
type Radius = Float<br>
<br>-- now the shape type doesn&#39;t care which type of point you have, but requires that all the points are the same<br>
data Shape  a = Circle Center Radius<br>
                            | Polygon [Point a]<br><br><br>The main problem here, is that you want to hide the Cartesian and Spherical constructors and only use mkCartesian and mkSherical to make Points (so that they have the proper restrictions). But this prevents you from using pattern matching where you have the constructors hidden.<br>
<br>GADTs however will solve that:<br><br>data Point a where<br>  Cartesian :: (Cartesian_coord, Cartesian_coord) -&gt; Point CartesianP<br>  Spherical :: (Latitude, Longitude)-&gt; Point SphericalP<br><br>Hope that helps :)<br>
<br>- Job<br><br><div class="gmail_quote">On Thu, Mar 18, 2010 at 12:20 AM, Darrin Chandler <span dir="ltr">&lt;<a href="mailto:dwchandler@stilyagin.com">dwchandler@stilyagin.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
Trying to get up to speed in Haskell, I&#39;m playing with doing some<br>
abstraction in data types. Specifically, I have this:<br>
<br>
type Cartesian_coord = Float<br>
<br>
type Latitude  = Float<br>
type Longitude = Float<br>
<br>
data Point      = Cartesian (Cartesian_coord, Cartesian_coord)<br>
                | Spherical (Latitude, Longitude)<br>
<br>
type Center = Point<br>
type Radius = Float<br>
<br>
data Shape      = Circle Center Radius<br>
                | Polygon [Point]<br>
<br>
This obviously stinks since a Polygon could contain mixed Cartesian and<br>
Spherical points. Polygon needs to be one or the other, but not mixed.<br>
<br>
I could define seperate types for Cartesian and Spherical and seperate<br>
CartesianPoly and SphericalPoly, but that doesn&#39;t seem very elegant and<br>
also increases as I add more coordinate systems and shapes. I read a<br>
little on GADTs, et al, but I&#39;m not sure if that&#39;s what I want for this<br>
or not.<br>
<br>
Any help appreciated!<br>
<font color="#888888"><br>
--<br>
Darrin Chandler            |  Phoenix BSD User Group  |  MetaBUG<br>
<a href="mailto:dwchandler@stilyagin.com">dwchandler@stilyagin.com</a>   |  <a href="http://phxbug.org/" target="_blank">http://phxbug.org/</a>      |  <a href="http://metabug.org/" target="_blank">http://metabug.org/</a><br>

<a href="http://www.stilyagin.com/" target="_blank">http://www.stilyagin.com/</a>  |  Daemons in the Desert   |  Global BUG Federation<br>
</font><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">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>