[Haskell-cafe] Random thoughts about typeclasses

Dominique Devriese dominique.devriese at cs.kuleuven.be
Wed May 18 11:24:38 CEST 2011


2011/5/16 Robert Clausecker <fuzxxl at gmail.com>:
> I found out, that GHC implements typeclasses as an extra argument, a
> record that stores all functions of the typeclass. So I was wondering,
> is there a way (apart from using newtype) to pass a custom record as the
> typeclass record, to modify the behavior of the typeclass? I thought
> about something like this:

You may be interested in Agda's upcoming "instance arguments"
(inspired upon Scala implicits and Agda's implicit arguments). These
will be available in Agda 2.2.12 (you may find references to an older
name "non-canonical implicit arguments"). The new type of function
arguments are automatically inferred from call-site scope unless they
are explicitly provided. Type classes are directly (not just under the
hood) modelled as records, and you can do what you suggest. You can
also define "local instances", and there are other advantages. We have
chosen a more limited-power instance search though. More discussion


I believe a similar Haskell extension (perhaps with a less principled
instance search) would improve and simplify Haskell's type class

By the way, Kahl and Scheffczyk proposed extending Haskell with "named
instances" in 2001 which allowed something like this to a limited
extent. Look for "Named instances for Haskell Type Classes" in Google


More information about the Haskell-Cafe mailing list