Hi,

Trying to get up to speed in Haskell, I'm playing with doing some
abstraction in data types. Specifically, I have this:

type Cartesian_coord = Float

type Latitude  = Float
type Longitude = Float

data Point      = Cartesian (Cartesian_coord, Cartesian_coord)
                | Spherical (Latitude, Longitude)

type Center = Point
type Radius = Float

data Shape      = Circle Center Radius
                | Polygon [Point]

This obviously stinks since a Polygon could contain mixed Cartesian and
Spherical points. Polygon needs to be one or the other, but not mixed.

I could define seperate types for Cartesian and Spherical and seperate
CartesianPoly and SphericalPoly, but that doesn't seem very elegant and
also increases as I add more coordinate systems and shapes. I read a
little on GADTs, et al, but I'm not sure if that's what I want for this
or not.

Any help appreciated!

-- 
Darrin Chandler            |  Phoenix BSD User Group  |  MetaBUG
dwchand...@stilyagin.com   |  http://phxbug.org/      |  http://metabug.org/
http://www.stilyagin.com/  |  Daemons in the Desert   |  Global BUG Federation

Attachment: pgpAUutRRKRWb.pgp
Description: PGP signature

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to