[Haskell-cafe] Template haskell instance checking

Simon Peyton-Jones simonpj at microsoft.com
Thu Mar 2 03:11:47 EST 2006

Not at the moment, I'm afraid, but it's the kind of question that TH
ought to be able to answer.  I could offer guidance if someone wanted to
implement it.


| -----Original Message-----
| From: haskell-cafe-bounces at haskell.org
[mailto:haskell-cafe-bounces at haskell.org] On Behalf Of
| heatsink
| Sent: 02 March 2006 00:55
| To: haskell-cafe at haskell.org
| Subject: [Haskell-cafe] Template haskell instance checking
| Is there a way, in template haskell, to find out what instance
| exist?  I'm not trying to accomplish anything specific right now, but
I can
| see two potential uses for this.  One is to emit compile-time error
| from TH code which would be more informative than the typechecker's
| The other is to produce TH functions that conditionally generate code
| depending on the instances satisfied by their arguments.
| I offer the following as a motivational example.  Suppose you want to
| an extensible library to handle files for, e.g., image data:
| class FileFormat a where
| formatName :: a -> String
| read :: Handle -> IO a
| write :: Handle -> a -> IO ()
| instance FileFormat TheStandardFormat where ....
| class (FileFormat a, FileFormat b) => Convert a b where
| convert :: a -> b
| Now it would be nice to generate instances of (Convert a
| Convert TheStandardFormat b) => Convert a b _except_ where there is an
| explicit definition for (Convert a b).  AFAIK, there's no way to do
this at
| present, but it seems like something that could be computed in TH.
| --heatsink
| _______________________________________________
| Haskell-Cafe mailing list
| Haskell-Cafe at haskell.org
| http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list