In PureScript, we use typeclasses to achieve a similar functionality to Go’s interfaces. The Geometry typeclass defines the methods area and perim, which are then implemented for the Rect and Circle types.
The measure function takes a type constraint Geometry a =>, which allows it to work with any type that implements the Geometry typeclass.
To run this program, you would typically compile it with the PureScript compiler and then run it with Node.js:
This example demonstrates how PureScript uses typeclasses to achieve polymorphism, similar to how interfaces are used in other languages. The typeclass system in PureScript is more powerful and flexible than traditional interfaces, allowing for features like multiple parameter typeclasses and functional dependencies.