# Shapes Compiling Error

4 messages
Open this post in threaded view
|

## Shapes Compiling Error

 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_______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe
Open this post in threaded view
|

## Re: Shapes Compiling Error

 Hi, Am Sonntag, 19. Februar 2006 22:57 schrieb Chatzianastassiou Achilleas: > 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... [snip code] ever heard of the layout-rule? You must indent the cases for polyArea to exactly the same level as the type-declaration, and all declarations in the let-binding to the same level. Once the indentation is corrected, you get the real error messages -- those you should understand easily. Cheers, Daniel -- "In My Egotistical Opinion, most people's C programs should be indented six feet downward and covered with dirt."         -- Blair P. Houghton _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe