He escrito una función en Haskell que toma tres puntos en el avión, y comprueba si están en línea recta, o gire a la derecha o izquierda.La función de Haskell no termina
tope aquí tienes el código:
detDirection :: Point -> Point -> Point -> Direction
detDirection [email protected](Point (x1, y1)) [email protected](Point (x2, y2)) c
= if (collinear1 a b c)
then Straight
else let
ab = Vector [x2 - x1, y2 - y1]
angleAbX = angle ab (Vector [1, 0])
(Point (x1, y1)) = turnAtP a b angleAbX
(Point (x2, y2)) = turnAtP a c angleAbX
in if (y1 > y2)
then Right
else Left
he probado collinear1
, angle
, turnAtP
en GHCi, y todos ellos terminará inmediatamente. detDirection
, sin embargo, sigue funcionando para siempre.
¿Puede alguien decirme dónde está el problema aquí?
¿Intenté recorrerlo línea por línea? –
Activa las advertencias (': set -Wall' en GHCi) y obtendrás algunas indicaciones claras de lo que hiciste mal. – ephemient