[Haskell-cafe] rewrite rules to specialize function according to type class?

Max Bolingbroke batterseapower at hotmail.com
Tue Feb 15 11:56:31 CET 2011

2011/2/15 Simon Peyton-Jones <simonpj at microsoft.com>:
> but currently any pragmas in a class decl are treated as attaching to the *default method*, not to the method selector:

I see. I didn't realise that that was what was happening. Personally I
find this a bit surprising, but I can see the motivation. Of course, a
sensible alternative design would be to have them control the
selectors, and then you could declare that you want your default
methods to be inlined like this:

class MyClass a where
  foo :: a -> a
  foo = default_foo

{-# INLINE default_foo #-}
default_foo = ... big expression ...

I think this design+workaround is slightly preferable to your proposal
because it avoids clients of a library defining a class from having to
write instances with decorated names. But maybe it's not such a big
win as to be worth making the change.

In any event, perhaps it would be worth warning if you write an INLINE
pragma for some identifier in a class declaration where no
corresponding default method has been declared, in just the same way
you would if you wrote an INLINE pragma for a non-existant binding?


More information about the Haskell-Cafe mailing list