Shapes Compiling Error

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Shapes Compiling Error

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...

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
Reply | Threaded
Open this post in threaded view
|

Re: Shapes Compiling Error

Daniel Fischer-4
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
Reply | Threaded
Open this post in threaded view
|

Re: Shapes Compiling Error

Cale Gibbard
In reply to this post by Chatzianastassiou Achilleas
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 <[hidden email]> 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
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Shapes Compiling Error

Chatzianastassiou Achilleas
Thanks everybody,

I think it was the layout thing that I misstyped plus the
area (RtTriangle s1 s1) = s1 *s2 /2

(silly me!)

Skag55

_________________________________________________________________
Don’t just search. Find. Check out the new MSN Search!
http://search.msn.click-url.com/go/onm00200636ave/direct/01/

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe