dfeuer
dfeuer

Reputation: 48591

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.

Upvotes: 16

Views: 210

Answers (1)

dfeuer
dfeuer

Reputation: 48591

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.

Upvotes: 3

Related Questions