Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partial application of strict constructors

Suppose I have

data Foo a = Foo !Int a [a] | Bar [a]

so the Foo constructor is strict in its first argument, which will be unpacked. Suppose further that I'm passing Foo n to a higher-order function f and that f does not get inlined (so Foo n is actually passed). The Core I get with -O2 indicates that n gets boxed and then passed to Foo, and the result is passed to f. My question: would I be better off calling

f (\a b -> Foo n a b)

to avoid boxing n? Or would that lead to some other performance problem?


I was actually thinking to define

foo' !n = \a b -> Foo n a b

and call f (foo' n), which I figured should do the same thing, but I guess it's better to ask specifically.

like image 543
dfeuer Avatar asked Apr 24 '16 01:04

dfeuer


1 Answers

I opened GHC Trac ticket 12990 for this. Reid Barton and Simon Peyton Jones suggested a fix (allowing the wrapper function to be inlined when partially applied), which I submitted as GHC Phabricator differential D2891. The patch has been applied to the master branch and will be included in GHC 8.2.

like image 182
dfeuer Avatar answered Nov 06 '22 21:11

dfeuer