1
votes

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
1

1 Answers

6
votes

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