Reputation:
I wrote the following code and put the error in the title. Can someone help me please? Error in line 7
punkteImKreis :: Double -> [(Double, Double)]
punkteImKreis k = [(x,y)|x <- [1.0,2.0..k-1.0],
y <- [1.0,2.0..k-1.0] ]
anteilImKreis :: Double -> Double
let l = length(punkteImKreis)
in anteilImKreis k = (fromIntegral (l)) / k^2
Upvotes: 1
Views: 247
Reputation: 8477
The error is in this definition:
anteilImKreis :: Double -> Double
let l = length(punkteImKreis)
in anteilImKreis k = (fromIntegral (l)) / k^2
let
is an expression; therefore, it has to be inside a definition (that is, on the right of an =
sign). This should be:
anteilImKreis :: Double -> Double
anteilImKreis k =
let l = length(punkteImKreis)
in (fromIntegral (l)) / k^2
By the way, you don't really need parentheses around an argument of a function when it's just one identifier. I would rewrite this as follows:
anteilImKreis :: Double -> Double
anteilImKreis k =
let l = length punkteImKreis
in (fromIntegral l) / k^2
Additionally, this exposes another error. punkteImKreis
isn't a list; it's a function which returns a list, which means you can't directly take its length
. I would assume you meant the following:
anteilImKreis :: Double -> Double
anteilImKreis k =
let l = length (punkteImKreis k)
in (fromIntegral l) / k^2
Upvotes: 5