# too many specialisations for one function

Simon Peyton-Jones simonpj at microsoft.com
Tue Sep 16 05:34:15 EDT 2008

```Interesting idea Neil.   Roman: I think you only need deep specialisation on non-recursive constructors, don't you?

Simon

| -----Original Message-----
| From: Mitchell, Neil [mailto:neil.mitchell.2 at credit-suisse.com]
| Sent: 15 September 2008 17:51
| To: Simon Peyton-Jones; cvs-ghc at haskell.org
| Cc: Roman Leshchinskiy
| Subject: RE: too many specialisations for one function
|
| > OK I have this figured out.  Consider this (from
| >
| > dropComment (' ':'-':'-':' ':_) = []
| > dropComment (x:xs) = x : dropComment xs
| > dropComment [] = []
| >
| > This desugars thus:
| >
| > dropComment xs
| >   = case xs of
| >       (C# x1 : xs1) ->
| >         case x1 of
| >           ' '# ->
| >              case xs1 of
| >                (C# x2:xs2) ->
| >                  case x2 of
| >                    '-' -> ....
| >                    DEFAULT -> dropComment (C# x2 : xs2)
| >           DEFAULT -> ...
| >        [] -> ...
|
| One possible heuristic would be to never specialise down recursive
| components. That way you would only ever obtain the specialisations:
|
| []
| _:_
| ' ':_
| '-':_
|
| Which seems like a sensible set. By using a size bound as well, your
| definition of recursive components can be very weak - directly recursive
| should catch most examples. I'm not sure how this work with other
| examples - it seems sufficient for the classic 'last' example though.
|
| Thanks
|
| Neil
|
| ==============================================================================
| Please access the attached hyperlink for an important electronic communications disclaimer:
|
| http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
| ==============================================================================
|

```