Henning Thielemann lemming at henning-thielemann.de
Mon Apr 16 11:11:15 EDT 2007

On Mon, 16 Apr 2007, Gaetano Caruana wrote:

> Hi all. I am new to this list ;) Today I have encountered something new that
> has never happened to me in the past 6 months that I have been using ghci
>
> I wrote this function:
>
>
> type Line = (Point,Point)
> type Point = (Float,Float)
>
> circleLineIntersection :: Float -> Float -> Float -> Line -> Maybe [Point]
> circleLineIntersection h k r ((x1,y1),(x2,y2)) = do

no 'do' is needed here

>                                                     let
>                                                         perpdist =
> calcPerpDist (h,k) ((x1,y1),(x2,y2))
>                                                         noSolution =
> perpdist > r
>                                                         oneSolution =
> perpdist  == r
>                                                         twoSolutions =
> perpdist < r

case compare perpdist r of
GT ->
EQ ->
LT ->

...

>                                                      in
>                                                         do
>                                                           if noSolution then
>                                                               Nothing
>                                                            else
>                                                               let
>                                                                   dx = x2 -
> x1
>                                                                   dy = y2 -
> y1
>                                                                   dr = sqrt
> (dx * dx + dy * dy)

Why computing sqrt if you only use dr*dr?

>                                                                   bigD = x1
> * y2 - x2 * y1
>                                                                   x1 = (
> bigD * dy + sign (dy) * dx  * sqrt( r * r * dr * dr - bigD * bigD  ) ) / (dr
> * dr)
>                                                                   y1 = -
> bigD * dx + abs(dy) * sqrt( r * r * dr * dr - bigD * bigD  )  / (dr * dr)
>                                                                   x2 = (
> bigD * dy - sign (dy) * dx  * sqrt( r * r * dr * dr - bigD * bigD  ) ) / (dr
> * dr)
>                                                                   y2 = -
> bigD * dx - abs(dy) * sqrt( r * r * dr * dr - bigD * bigD  )  / (dr * dr)

ghci -Wall should have warned you, that y2 shadows function argument y2.
Thus you programmed an infinite cycle.