我在Haskell中编写了一个函数,它在飞机上需要三个点, 并检查它们是否在一条直线上,或者右转或左转。Haskell函数不终止
Here's代码:
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
从来就在GHCI测试collinear1
,angle
,turnAtP
,他们都立即终止。然而, detDirection
会一直运行。
有人能告诉我这里的问题在哪里吗?
试图逐行逐行通过它? – 2010-01-24 23:01:00
打开GHCi中的':set-Wall'的警告,你会清楚地知道你做错了什么。 – ephemient 2010-01-25 05:11:37