Functional programming provides strong foundations for developing reliable and secure software systems, yet its adoption remains not widespread due to the steep learning curve. Recent advances in Large Language Models (LLMs) for code generation present new opportunities to lower these barriers. However, extensive evaluations of LLMs largely focus on imperative programming languages, and their capabilities in functional programming languages (FP) remain underexplored. To address this gap, we introduce FPEval, a holistic evaluation framework built on FPBench, a new benchmark of 721 programming tasks across three difficulty levels on three mainstream FP languages: Haskell, Ocaml and Scala. FPEval provides compehensive evaluation infrastructures with both test validations with comprehensive test suites and static analysis tools to assess both functional correctness and code style and maintainability. Using this framework, we evaluate state-of-the-art LLMs, including GPT-3.5, GPT-4o, and GPT-5, for code generation in functional programming languages and Java as an imperative baseline. Our results demonstrate that LLM performance in functional programming improves substantially with model advancement; however, error rates remain significantly higher in purely functional languages (Haskell and OCaml) than in hybrid (Scala) or imperative (Java) languages. Moreover, LLMs frequently generate non-idiomatic functional code that follows imperative patterns, raising concerns about code style and long-term maintainability. Finally, we show that LLMs can partially self-repair both correctness and quality issues when provided with static analysis feedback and hand-crafted instructions for common types of issues.


翻译:函数式编程为开发可靠且安全的软件系统提供了坚实基础,但由于其陡峭的学习曲线,其采用仍不广泛。近期用于代码生成的大语言模型(LLMs)的进展为降低这些障碍提供了新的机遇。然而,现有对LLMs的大规模评估主要集中于命令式编程语言,其在函数式编程语言(FP)中的能力仍未得到充分探索。为填补这一空白,我们提出了FPEval,这是一个基于FPBench构建的整体性评估框架。FPBench是一个包含721个编程任务的新基准,涵盖三种主流函数式语言(Haskell、Ocaml和Scala)的三个难度级别。FPEval提供了全面的评估基础设施,包括基于综合测试套件的测试验证以及静态分析工具,以评估功能正确性、代码风格和可维护性。利用该框架,我们评估了包括GPT-3.5、GPT-4o和GPT-5在内的最先进LLM在函数式编程语言中的代码生成能力,并以Java作为命令式基线。我们的结果表明,随着模型进步,LLM在函数式编程中的性能显著提升;然而,在纯函数式语言(Haskell和OCaml)中的错误率仍显著高于混合式(Scala)或命令式(Java)语言。此外,LLM经常生成遵循命令式模式的非惯用函数式代码,这引发了关于代码风格和长期可维护性的担忧。最后,我们证明,当提供静态分析反馈以及针对常见问题类型的手工编写指令时,LLM能够部分自我修复功能正确性和代码质量问题。

0
下载
关闭预览

相关内容

人们为了让计算机解决各种棘手的问题,使用编程语言 编写程序代码并通过计算机运算得到最终结果的过程。
【ETZH博士论文】语言模型编程
专知会员服务
25+阅读 · 2025年6月14日
面向统计学家的大型语言模型概述
专知会员服务
32+阅读 · 2025年3月16日
《大型语言模型代码生成》综述
专知会员服务
68+阅读 · 2024年6月4日
天大最新《大型语言模型评估》全面综述,111页pdf
专知会员服务
88+阅读 · 2023年10月31日
自然语言处理中的语言模型预训练方法
PaperWeekly
14+阅读 · 2018年10月21日
用于数学的 10 个优秀编程语言
算法与数据结构
13+阅读 · 2018年1月5日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
3+阅读 · 2014年12月31日
VIP会员
相关基金
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
3+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员