
Robert,
2011/5/16 Robert Clausecker
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 online. http://wiki.portal.chalmers.se/agda/pmwiki.php?n=ReferenceManual.InstanceArg... http://people.cs.kuleuven.be/~dominique.devriese/agda-instance-arguments/ I believe a similar Haskell extension (perhaps with a less principled instance search) would improve and simplify Haskell's type class system. 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 Scholar. Dominique