#5059: Pragma to SPECIALISE on value arguments
---------------------------------+------------------------------------------
    Reporter:  batterseapower    |       Owner:              
        Type:  feature request   |      Status:  new         
    Priority:  normal            |   Component:  Compiler    
     Version:  7.0.3             |    Keywords:              
    Testcase:                    |   Blockedby:              
          Os:  Unknown/Multiple  |    Blocking:              
Architecture:  Unknown/Multiple  |     Failure:  None/Unknown
---------------------------------+------------------------------------------
 I've sometimes found myself wishing for this pragma to get some "partial
 evaluation on the cheap". The idea is to allow something like:

 {{{
 defaultOpts :: Options
 defaultOpts = ...

 {-# SPECIALISE f defaultOpts :: Int -> Int #-}
 f :: Options -> Int -> Int
 f opts x = ... f opts ...
 }}}

 This would desugar into this additional code:

 {{{
 {-# RULES "f/spec" f defaultOpts = f_spec_1 #-}
 f_spec_1 = (\opts x -> ... ... f opts ...) defaultOpts -- NB: body of f
 duplicated
 }}}

 The hope is that the simplifier and RULE matcher will tidy this up so we
 get a nice loop back to f_spec_1 with the body of the function specialised
 for the particular opts.

 This is useful when functions are called often with particular arguments.
 An example would be where "f" is an edit-distance function which takes
 costs to be assigned to each edit, strings to be compared and returns an
 integer distance. In my library, the costs are given almost always going
 to be the default ones so I want to make that case fast, but I want to
 allow the user to supply their own set.

 This pragma is somewhat subsumed by:

   1. SpecConstr, if the options are algebraic data/literals that are also
 scrutinised by the body of f

   2. Static argument transformation, except that the RULE based strategy
 achieves more code sharing compared to SAT

 I think that pragma might be a relatively simple to implement nice-to-have
 feature.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/5059>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to