Assuming that we need to calculate the area of each Shape polymorphically.
In C# we would normally create a hypothetical object hierarchy and a Visitor. In this example, we would have to create a ShapeVisitor class and then a derived ShapeAreaCalculator visitor class.
In F#, we can use Pattern Matching on the Shape
type:
let rectangle = Rectangle(1.3, 10.0)
let circle = Circle (1.0)
let calculateArea shape =
match shape with
| Circle radius -> 3.141592654 * radius * radius
| Rectangle (height, width) -> height * width
let rectangleArea = calculateArea(rectangle)
// -> 1.3 * 10.0
let circleArea = calculateArea(circle)
// -> 3.141592654 * 1.0 * 1.0