Class instance specificity order (was Re: Fundeps and type equality)

Simon Peyton-Jones simonpj at microsoft.com
Thu Jan 10 23:17:05 CET 2013


Is http://www.haskell.org/ghc/docs/latest/html/users_guide/type-class-extensions.html#instance-overlap 
insufficiently clear?  If so, let's clarify it.

Simon

|  -----Original Message-----
|  From: Tyson Whitehead [mailto:twhitehead at gmail.com]
|  Sent: 10 January 2013 22:12
|  To: glasgow-haskell-users at haskell.org
|  Cc: Richard Eisenberg; Martin Sulzmann; Simon Peyton-Jones
|  Subject: Class instance specificity order (was Re: Fundeps and type equality)
|  
|  On January 10, 2013 13:56:02 Richard Eisenberg wrote:
|  > Class instances that overlap are chosen among by order of specificity;
|  
|  Sorry to jump in the middle here, but this caught my attention as this sort of
|  specificity determination is exactly what I had in mind when I was working on
|  my "The shape of things: a reason for type preference" paper.
|  
|  I would love to know what approach GHC is currently taking to determine this.
|  The document gives the example of matching C Int [Int] against
|  
|  C Int a
|  C a Bool
|  C Int [a]
|  C Int [Int]
|  
|  This is easy though.  Obviously the last match is best because it is exact.
|  What if we have something like C Int [[Int]] against
|  
|  C Int b
|  C a [[b]]
|  
|  though.  How is the best match determined in this case?
|  
|  Thanks!  -Tyson




More information about the Glasgow-haskell-users mailing list