[Haskell-cafe] Shapes Compiling Error

Chatzianastassiou Achilleas achatzianastassiou at hotmail.com
Sun Feb 19 16:57:14 EST 2006


Hi everybody,

I have written some code for several shapes, and i get a compiling error:

  parse error on input `:'

though I can't find where the error is...

data Shape = Ellipse Radius Radius
			| Polygon [Vertex]

	deriving Show

type Radius = Float
type Vertex = (Float, Float)


area :: Shape -> Float
area (Rectangle s1 s2) = s1 * s2
area (RtTriangle s1 s1) = s1 *s2 /2
area (Ellipse r1 r2) = pi * r1 * r2
area (Polygon(v1:v2:v3:vs))
	= triArea v1 v2 v3 + area(Polygon(v1:v3:vs))
area(Polygon _ )
	= 0
area (Polygon(v1:vs')) = polyArea vs
	where polyArea			   :: [Vertex] -> Float
		  polyArea(v2:v3:vs')   = triArea v1 v2 v3
									+ polyArea(v3:vs')
		  polyArea _ 			= 0

triArea :: Vertex -> Vertex -> Vertex -> Float
triArea v1 v2 v3 = 	let	a = distBeetween v1 v2
						b = distBeetween v2 v3
						c = distBeetween v3 v1
						s = 0.5 * (a + b + c)
					in sqrt (s * (s - a) * (s - b) * (s - c))

distBeetween :: Vertex -> Vertex -> Float
distBeetween (x1, y1) (x2, y2)
				= sqrt ((x1 - x2) ^ 2 + (y1 - y2) ^ 2)



Any suggestions?

Thanks in advance,

Skag55

_________________________________________________________________
On the road to retirement? Check out MSN Life Events for advice on how to 
get there! http://lifeevents.msn.com/category.aspx?cid=Retirement



More information about the Haskell-Cafe mailing list