[Haskell-cafe] Abstraction in data types

Darrin Chandler dwchandler at stilyagin.com
Thu Mar 18 00:20:49 EDT 2010


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
dwchandler at stilyagin.com   |  http://phxbug.org/      |  http://metabug.org/
http://www.stilyagin.com/  |  Daemons in the Desert   |  Global BUG Federation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20100317/aec7ccf9/attachment.bin

More information about the Haskell-Cafe mailing list