Skip to content

John Cowan on Comparators: A Dynamic Type Class for Scheme

Photo of Pierre de Lacaze
Hosted By
Pierre de L.
John Cowan on Comparators: A Dynamic Type Class for Scheme

Details

Haskell type classes such as Eq and Ord provide an escape hatch from ML-style polymorphic static typing, allowing ad-hoc polymorphism of the functions defined in a type class. They are implemented by GHC using a record of functions, one for each function declared in the type class. While developing Scheme libraries for the ongoing R7RS-large standard, I found a need to parameterize collections such as sets and hash tables with appropriate monomorphic procedures applicable to their elements. The implementation method evolved over time to converge on the same solution, made directly accessible to the Scheme programmer using a new data type: comparators, which are a dynamically typed equivalent of type class Ord.

Photo of LispNYC group
LispNYC
See more events
Meetup HQ, 9th Floor
632 Broadway · New York, NY