{"status":"ok","message-type":"work","message-version":"1.0.0","message":{"indexed":{"date-parts":[[2026,9,26]],"date-time":"2026-09-26T12:00:46Z","timestamp":1790424046889,"version":"4.1.0"},"reference-count":61,"publisher":"Association for Computing Machinery (ACM)","issue":"OOPSLA1","license":[{"start":{"date-parts":[[2026,4,10]],"date-time":"2026-04-10T00:00:00Z","timestamp":1775779200000},"content-version":"vor","delay-in-days":0,"URL":"https:\/\/creativecommons.org\/licenses\/by\/4.0\/legalcode"}],"funder":[{"DOI":"10.13039\/501100001459","name":"Ministry of Education - Singapore","doi-asserted-by":"publisher","award":["T1 251RES2422"],"award-info":[{"award-number":["T1 251RES2422"]}],"id":[{"id":"10.13039\/501100001459","id-type":"DOI","asserted-by":"publisher"}]}],"content-domain":{"domain":["dl.acm.org"],"crossmark-restriction":true},"short-container-title":["Proc. ACM Program. Lang."],"published-print":{"date-parts":[[2026,4,10]]},"abstract":"<jats:p>\n                    Rank-2 polymorphism, when combined with type-class-constrained arguments, enables powerful abstractions and code reuse by allowing functions to accept arguments that are themselves ad-hoc polymorphic. Optimizing compilers like the Glasgow Haskell Compiler (GHC) use techniques like class-dictionary specialization and inlining for optimization. However, these techniques can falter when the rank-2 polymorphic functions are recursive. Specializing the polymorphic arguments of recursive rank-2 polymorphic function applications requires inlining the applied function to expose type and dictionary applications to the arguments, but the compiler\u2019s heuristic-driven inliner is reluctant to inline recursive functions, risking non-termination during compilation. This stalemate causes recursive rank-2 polymorphic functions to remain un-optimized and be left with a runtime penalty. Within the Haskell ecosystem, we identify this stalemate within three widely used libraries: the Scrap Your Boilerplate (SYB) and SYB With Class (SYB3) generic-programming libraries, and a fragment of the\n                    <jats:monospace>lens<\/jats:monospace>\n                    optics library. In these libraries, the combination of rank-2 polymorphism, type-class constraints and recursion is central to their implementation.\n                  <\/jats:p>\n                  <jats:p>\n                    In this paper, we present a new optimization technique that breaks this stalemate and enables class-dictionary specialization with recursive rank-2 polymorphic functions. We introduce a partial evaluator that strategically applies the standard transformations of inlining,\n                    <jats:italic toggle=\"yes\">\u03b2<\/jats:italic>\n                    -reduction and memoization to applications of rank-2 polymorphic functions that are\n                    <jats:italic toggle=\"yes\">partially static<\/jats:italic>\n                    , i.e., whose arguments have some information known statically. This process exposes applications of its polymorphic arguments onto concrete types and dictionaries, which can be specialized by the standard compiler optimization pipeline. Additionally, we introduce type-constant folding to evaluate run-time type-equality tests statically, further leveraging static type information gained from partial evaluation. We implement our technique as a GHC plugin and demonstrate its effectiveness by resolving the performance bottlenecks in the aforementioned Haskell libraries. On SYB and SYB3 traversals, our technique achieves speedups of 43\u00d7 on average (up to 155\u00d7) and 6.1\u00d7 on average (up to 9.5\u00d7), respectively, matching the performance of their hand-written counterparts. On the fragment of the\n                    <jats:monospace>lens<\/jats:monospace>\n                    library containing the identified slowdowns, our technique achieves speedups of 1.6\u00d7 on average (up to 2.1\u00d7).\n                  <\/jats:p>","DOI":"10.1145\/3798227","type":"journal-article","created":{"date-parts":[[2026,4,10]],"date-time":"2026-04-10T14:33:43Z","timestamp":1775831623000},"page":"766-793","update-policy":"https:\/\/doi.org\/10.1145\/crossmark-policy","source":"Crossref","is-referenced-by-count":0,"title":["Class-Dictionary Specialization with Rank-2 Polymorphic Functions"],"prefix":"10.1145","volume":"10","author":[{"ORCID":"https:\/\/orcid.org\/0009-0007-9357-0158","authenticated-orcid":false,"given":"Yong Qi","family":"Foo","sequence":"first","affiliation":[{"name":"National University of Singapore, Singapore, Singapore"}],"role":[{"vocabulary":"crossref","role":"author"}]},{"ORCID":"https:\/\/orcid.org\/0000-0003-3160-6972","authenticated-orcid":false,"given":"Michael D.","family":"Adams","sequence":"additional","affiliation":[{"name":"National University of Singapore, Singapore, Singapore"}],"role":[{"vocabulary":"crossref","role":"author"}]}],"member":"320","published-online":{"date-parts":[[2026,4,10]]},"reference":[{"key":"e_1_3_1_2_2","doi-asserted-by":"publisher","DOI":"10.1145\/2364506.2364509"},{"key":"e_1_3_1_3_2","doi-asserted-by":"publisher","DOI":"10.1145\/2543728.2543730"},{"key":"e_1_3_1_4_2","doi-asserted-by":"publisher","DOI":"10.1016\/j.scico.2015.09.003"},{"key":"e_1_3_1_5_2","doi-asserted-by":"publisher","DOI":"10.1007\/978-3-540-27764-4_3"},{"key":"e_1_3_1_6_2","doi-asserted-by":"publisher","DOI":"10.1145\/3242744.3242748"},{"key":"e_1_3_1_7_2","doi-asserted-by":"publisher","DOI":"10.1145\/1596638.1596652"},{"key":"e_1_3_1_8_2","unstructured":"Manuel Chakravarty Gabriel Ditu and Roman Leshchinskiy. 2009. Instant Generics: Fast and Easy."},{"key":"e_1_3_1_9_2","doi-asserted-by":"publisher","DOI":"10.1145\/581690.581698"},{"key":"e_1_3_1_10_2","doi-asserted-by":"publisher","DOI":"10.2307\/j.ctv36xvknz.15"},{"key":"e_1_3_1_11_2","doi-asserted-by":"publisher","DOI":"10.1145\/2633628.2633634"},{"key":"e_1_3_1_12_2","volume-title":"System FC, as implemented in GHC","author":"Eisenberg Richard A.","year":"2015","unstructured":"Richard A. Eisenberg. 2015. System FC, as implemented in GHC. Technical Report. University of Pennsylvania."},{"key":"e_1_3_1_13_2","doi-asserted-by":"publisher","DOI":"10.1145\/2034675.2034690"},{"key":"e_1_3_1_14_2","doi-asserted-by":"publisher","DOI":"10.1145\/2364506.2364508"},{"key":"e_1_3_1_15_2","doi-asserted-by":"publisher","unstructured":"Yong Qi Foo and Michael D. Adams. 2026. Class-Dictionary Specialization With Rank-2 Polymorphic Functions (Artifact). doi:10.5281\/zenodo.18502345","DOI":"10.5281\/zenodo.18502345"},{"key":"e_1_3_1_16_2","doi-asserted-by":"publisher","DOI":"10.1145\/1232420.1232424"},{"key":"e_1_3_1_17_2","doi-asserted-by":"publisher","DOI":"10.1007\/3-540-11980-9_13"},{"key":"e_1_3_1_18_2","unstructured":"GHC Team. 2024. Glasgow Haskell Compiler\u2014The Glasgow Haskell Compiler. https:\/\/www.haskell.org\/ghc. Accessed: 18 September 2024."},{"key":"e_1_3_1_19_2","doi-asserted-by":"publisher","DOI":"10.1145\/3428217"},{"key":"e_1_3_1_20_2","doi-asserted-by":"publisher","DOI":"10.1145\/1411204.1411218"},{"key":"e_1_3_1_21_2","doi-asserted-by":"publisher","DOI":"10.1016\/S0167-6423(02)00025-4"},{"key":"e_1_3_1_22_2","doi-asserted-by":"publisher","DOI":"10.1145\/1016850.1016882"},{"key":"e_1_3_1_23_2","doi-asserted-by":"publisher","DOI":"10.1007\/11737414_3"},{"key":"e_1_3_1_24_2","doi-asserted-by":"publisher","DOI":"10.1007\/11783596_14"},{"key":"e_1_3_1_25_2","unstructured":"Industrial Haskell Group. 2024. Hackage: Total Downloads. https:\/\/hackage.haskell.org\/packages\/browse?terms=generic. Accessed: 18 September 2024."},{"key":"e_1_3_1_26_2","doi-asserted-by":"publisher","DOI":"10.1145\/263699.263763"},{"key":"e_1_3_1_27_2","doi-asserted-by":"publisher","DOI":"10.1007\/BF01019005"},{"key":"e_1_3_1_28_2","doi-asserted-by":"publisher","DOI":"10.5555\/153676"},{"key":"e_1_3_1_29_2","doi-asserted-by":"publisher","DOI":"10.1017\/S0956796802004331"},{"key":"e_1_3_1_30_2","doi-asserted-by":"publisher","DOI":"10.1145\/1929501.1929507"},{"key":"e_1_3_1_31_2","doi-asserted-by":"publisher","DOI":"10.1007\/978-3-319-07151-0_6"},{"key":"e_1_3_1_32_2","doi-asserted-by":"publisher","DOI":"10.1145\/3236780"},{"key":"e_1_3_1_33_2","unstructured":"Edward A. Kmett. 2015. lens. https:\/\/hackage.haskell.org\/package\/lens. Accessed: 18 September 2024."},{"key":"e_1_3_1_34_2","doi-asserted-by":"publisher","DOI":"10.1145\/604174.604179"},{"key":"e_1_3_1_35_2","doi-asserted-by":"publisher","DOI":"10.1145\/1016850.1016883"},{"key":"e_1_3_1_36_2","doi-asserted-by":"publisher","DOI":"10.1145\/1086365.1086391"},{"key":"e_1_3_1_37_2","doi-asserted-by":"publisher","DOI":"10.1145\/567067.567077"},{"key":"e_1_3_1_38_2","doi-asserted-by":"publisher","DOI":"10.1145\/3720472"},{"key":"e_1_3_1_39_2","volume-title":"Less Is More: Generic Programming Theory and Practice","author":"Magalh\u00e3es Jos\u00e9 Pedro","year":"2012","unstructured":"Jos\u00e9 Pedro Magalh\u00e3es. 2012. Less Is More: Generic Programming Theory and Practice. Ph. D. Dissertation. Universiteit Utrecht."},{"key":"e_1_3_1_40_2","doi-asserted-by":"publisher","DOI":"10.1145\/1706356.1706366"},{"key":"e_1_3_1_41_2","doi-asserted-by":"publisher","DOI":"10.1007\/978-3-642-41582-1_7"},{"key":"e_1_3_1_42_2","doi-asserted-by":"publisher","DOI":"10.5555\/940279"},{"key":"e_1_3_1_43_2","doi-asserted-by":"publisher","DOI":"10.1145\/378795.378858"},{"key":"e_1_3_1_44_2","doi-asserted-by":"publisher","DOI":"10.1145\/2804302.2804313"},{"key":"e_1_3_1_45_2","doi-asserted-by":"publisher","DOI":"10.1145\/1291201.1291208"},{"key":"e_1_3_1_46_2","doi-asserted-by":"publisher","DOI":"10.1007\/3-540-12925-1_41"},{"key":"e_1_3_1_47_2","doi-asserted-by":"publisher","DOI":"10.1007\/978-3-540-27861-0_11"},{"key":"e_1_3_1_48_2","volume-title":"2001 Haskell Workshop","author":"Jones Simon Peyton","year":"2001","unstructured":"Simon Peyton Jones, Andrew Tolmach, and Tony Hoare. 2001. Playing by the rules: rewriting as a practical optimisation technique in GHC. In 2001 Haskell Workshop (2001 haskell workshop ed.). ACM SIGPLAN. https:\/\/www.microsoft.com\/en-us\/research\/publication\/playing-by-the-rules-rewriting-as-a-practical-optimisation-technique-in-ghc\/","edition":"2001"},{"key":"e_1_3_1_49_2","doi-asserted-by":"publisher","DOI":"10.1007\/978-3-319-30936-1_16"},{"key":"e_1_3_1_50_2","unstructured":"Matthew Pickering Andres L\u00f6h and Nicolas Wu. 2020. A Specification for Typed Template Haskell. https:\/\/mpickering.github.io\/papers\/specification-typed-th.pdf."},{"key":"e_1_3_1_51_2","doi-asserted-by":"publisher","DOI":"10.1145\/3406088.3409021"},{"key":"e_1_3_1_52_2","doi-asserted-by":"publisher","DOI":"10.1145\/1411286.1411301"},{"key":"e_1_3_1_53_2","doi-asserted-by":"publisher","DOI":"10.1007\/978-3-642-41582-1_6"},{"key":"e_1_3_1_54_2","doi-asserted-by":"publisher","DOI":"10.1017\/S0956796814000185"},{"key":"e_1_3_1_55_2","doi-asserted-by":"publisher","DOI":"10.1145\/581690.581691"},{"key":"e_1_3_1_56_2","unstructured":"Bryan O\u2019 Sullivan. 2009. criterion. https:\/\/hackage.haskell.org\/package\/criterion. Accessed: 25 September 2025."},{"key":"e_1_3_1_57_2","doi-asserted-by":"publisher","DOI":"10.1145\/1190315.1190324"},{"key":"e_1_3_1_58_2","doi-asserted-by":"publisher","DOI":"10.1145\/5956.5957"},{"key":"e_1_3_1_59_2","volume-title":"Towards Getting Generic Programming Ready for Prime Time","author":"Yakushev Alexey Rodriguez","year":"2009","unstructured":"Alexey Rodriguez Yakushev. 2009. Towards Getting Generic Programming Ready for Prime Time. Ph.D. Dissertation. Utrecht University."},{"key":"e_1_3_1_60_2","doi-asserted-by":"publisher","DOI":"10.1145\/1596550.1596585"},{"key":"e_1_3_1_61_2","doi-asserted-by":"publisher","DOI":"10.1145\/2847538.2847546"},{"key":"e_1_3_1_62_2","doi-asserted-by":"publisher","DOI":"10.1145\/3110273"}],"container-title":["Proceedings of the ACM on Programming Languages"],"original-title":[],"language":"en","link":[{"URL":"https:\/\/dl.acm.org\/doi\/pdf\/10.1145\/3798227","content-type":"unspecified","content-version":"vor","intended-application":"similarity-checking"}],"deposited":{"date-parts":[[2026,9,26]],"date-time":"2026-09-26T11:22:56Z","timestamp":1790421776000},"score":1,"resource":{"primary":{"URL":"https:\/\/dl.acm.org\/doi\/10.1145\/3798227"}},"subtitle":[],"short-title":[],"issued":{"date-parts":[[2026,4,10]]},"references-count":61,"journal-issue":{"issue":"OOPSLA1","published-print":{"date-parts":[[2026,4,10]]}},"alternative-id":["10.1145\/3798227"],"URL":"https:\/\/doi.org\/10.1145\/3798227","relation":{},"ISSN":["2475-1421"],"issn-type":[{"value":"2475-1421","type":"electronic"}],"subject":[],"published":{"date-parts":[[2026,4,10]]},"assertion":[{"value":"2025-10-10","order":0,"name":"received","label":"Received","group":{"name":"publication_history","label":"Publication History"}},{"value":"2026-02-17","order":2,"name":"accepted","label":"Accepted","group":{"name":"publication_history","label":"Publication History"}},{"value":"2026-04-10","order":3,"name":"published","label":"Published","group":{"name":"publication_history","label":"Publication History"}}]}}