计算两点之间的距离(Haskell) [英] calculate distance between two points (Haskell)
本文介绍了计算两点之间的距离(Haskell)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
distance = sqrt((x1 - x2)^ 2 +(y1 - y2)^ 2)
所以我希望函数调用和输出如下所示:
<$ c $ >距离(5,10)(3,5)
- 5.385 ...
当我尝试在下面运行我的代码时,它告诉我在输入'where'时解析错误。任何人都可以帮我解决我的问题吗?这是我的代码:
距离(x1,y1)(x2,y2)= sqrt(x'* x'+ y '* y')
其中
x'= x1 - x2
y'= y1 - y2
解决方案
你正在做一个indendation错误,这应该可以工作 - 看看where子句是如何缩进的:
< pre $ distance(x1,y1)(x2,y2)= sqrt(x'* x'+ y'* y')
其中
x'= x1 - x2
y'= y1 - y2
Given an input of two tupples, i want to be able to calculate the distance between two points using the formula: distance = sqrt ( (x1 - x2) ^ 2 + (y1 - y2) ^2 )
so i want the function call and output to look like this:
-- > distance (5 , 10) (3 , 5)
-- 5.385...
when i try to run my code below, it tells me parse error on input 'where'. Can anyone help me resolve my issue? Here is my code:
distance (x1 , y1) (x2 , y2) = sqrt (x'*x' + y'*y')
where
x' = x1 - x2
y' = y1 - y2
解决方案
You are making an indendation error, this should work- see how where clause is indented:
distance (x1 , y1) (x2 , y2) = sqrt (x'*x' + y'*y')
where
x' = x1 - x2
y' = y1 - y2
这篇关于计算两点之间的距离(Haskell)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文