RULES and type classes

Simon Peyton-Jones simonpj at microsoft.com
Mon Sep 3 05:59:22 EDT 2007


| > In particular, it would be nice to be able to specialise based on the
| > instances, as we do for [a] --> [Int], e.g.
| >
| >     RULES sum = sumInt :: [Int] -> Int
| >
| > is fine in the current system. So I could imagine some nice
| > specialisations based on say, the good old Ord:
| >
| >     RULES nub = nubOrd :: (Eq a, Ord a) => [a] -> [a]
| >
| > which might use a Map, say.

This would be hard, because it'd mean that GHC's *rule rewrite engine* would need to be able to ask "is there an Ord instance for this type T?"  Currently the rule rewrite engine performs simple syntactic matching, which is a much much easier thing.  One could imagine a cleverer, type-class-aware optimisation pass, but I would suggest that it'd be cleaner to keep it separate from the nice simple rewrite engine.

Simon


More information about the Glasgow-haskell-users mailing list