我是 Haskell 的新手,我很难为这个程序加入两段代码。它所做的(或应该做的)是让我知道三角形是否根据 cosenes 定理等腰。这是我认为可行的方法:
--Determine if a triangle is isosceles by the cosene theroem
module Main where
sides :: (Float, Float, Float) -> (Float, Float, Float)
sides (a, b, c) = (x, y, z)
where
x = acos((b^2 + c^2 - a^2) / (2 * b * c))
y = acos((a^2 + c^2 - b^2) / (2 * a * c))
z = acos((a^2 + b^2 - c^2) / (2 * a * b))
theorem :: (Float, Float, Float) -> String
theorem (x, y, z)
|(x==y && x/=z) = "Es isosceles"
|(x==z && x/=y) = "Es isosceles"
|(y==z && y/=x) = "No es isosceles"
main :: IO()
main = do
print "Please type the size of the triangle faces: "
(a, b, c) <- getLine
(x, y, z) <- sides (a, b, c)
string <- theorem(x, y, z)
print string