Learning Haskell: list comprehensions in C#
c#, haskell, linq
Solution
Using Enumerable:
IEnumerable<double> SquareArea(IEnumerable<int> xs)
{
return from r in xs select Math.PI * r * r;
}
or
IEnumerable<double> SquareArea(IEnumerable<int> xs)
{
return xs.Select(r => Math.PI * r * r);
}
which is very close to Haskell's
squareArea xs = map (\r -> pi * r * r) xs
Problem
The following code is in Haskell. How would I write similar function in C#? ``` squareArea xs = [pi * r^2 | r <- xs] ``` Just to clarify... above code is a function, that takes as input a list containing radius of circles. The expression calculates area of each of the circle in the input list. I know that in C#, I can achieve same result, by looping thru a list and calculate area of each circle in the list and return a list containing area of circles. My question is... Can the above code be written in similar fashion in C#, perhaps using lambda expressions or LINQ?