给定两个tupples的输入,我希望能够使用以下公式计算两点之间的距离:distance = sqrt((x1 - x2)^ 2 +(y1 - y2)^ 2)
所以我希望函数调用和输出看起来像这样:
-- > distance (5 , 10) (3 , 5)
-- 5.385...
Run Code Online (Sandbox Code Playgroud)
当我尝试运行下面的代码时,它告诉我输入'where'的解析错误.任何人都可以帮我解决我的问题吗?这是我的代码:
distance (x1 , y1) (x2 , y2) = sqrt (x'*x' + y'*y')
where
x' = x1 - x2
y' = y1 - y2
Run Code Online (Sandbox Code Playgroud)
你正在做一个indendation错误,这应该工作 - 看看where子句是如何缩进的:
distance (x1 , y1) (x2 , y2) = sqrt (x'*x' + y'*y')
where
x' = x1 - x2
y' = y1 - y2
Run Code Online (Sandbox Code Playgroud)