Nested UNPACK in GHC

I often collect several values โ€‹โ€‹in tuples, since I consider tuples to be a natural type for this. However, tuples are not strict. Therefore consider

data A

data B =
    B !A

data C =
    C !(B, B)

data D =
    D !B !B

With -funbox-strict-fieldsand optimization, UNPACKs are nested. Will the tuple in be Cunpacked in C A Aas with D, or simply C B B? Here is the link in the GHC-doc: 7.16. Pragmas .

(are non-empty type types? type-constructors?)

+5
source share
1 answer

Consider:

data B = B !Int

data C = C !(B, B)

data D = D !B !B

b0 = B 7
b1 = B 4

c = C (b0, b1)

d = D b0 b1

Where

data (,) a b = (a,b)

GHC will gladly erase nested strict constructors (!B), and it will make C strict in its first field, optimizing:

b0 = B 7
b1 = B 4

c = C b0 b1

d = D 7 4

, , (,) , GHC . , , , .

- . , (, , ).


, - , . , .

+6

All Articles