[Haskell-cafe] Shapes Compiling Error
Cale Gibbard
cgibbard at gmail.com
Sun Feb 19 17:58:07 EST 2006
Watch how deeply things are indented. The definitions for polyArea
should be indented to the same level as its type signature. Currently,
they're indented a little more, so the first line of polyArea's
definition is being treated as part of the type signature, which is
why you're getting the error. GHC/GHCi/hugs should be telling you also
what line the error happens on, which should be a good clue here :)
- Cale
On 19/02/06, Chatzianastassiou Achilleas <achatzianastassiou at hotmail.com> wrote:
> 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
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list