An Object-Oriented approach

When coming from an Object-Oriented background, you would associate a shape with an interface (in Java terminology). Haskell has a construct that looks a lot like interfaces, called classes. We’ll define a class Shape.

A Circle takes a center point and a radius. Note that, until now on, we are writing our Haskell program in more or less the same way as we would write it in Java. The real problem arises when we want to declare our list of arbitrary shapes. In ghci:

Oh yes, we should’ve thought of that: all elements in a list must be of the same type1. We’re doing it wrong2.

A more functional approach

We need to stop thinking of classes here. Because a Shape is a collection of arbitrary points, we could consider a Shape as a function. This function would, for any Point, return True when this Point lies in the Shape.