λ 演算中的多个阶乘
Many Factorials in Lambda Calculus

原始链接: https://text.marvinborner.de/2025-10-08-12.html

## Bruijn 中的多种阶乘实现 这篇文章展示了在 Bruijn 编程语言中计算阶乘的多种方法——一种使用 de Bruijn 指标的无类型 lambda 演算的极简语法。作者在 16 小时的飞行中探索了不同的方法,并将其中一些方法构建为有趣的谜题。 示例从基本的递归定义到更复杂的技术,利用组合子、CPS(Continuation Passing Style),甚至避免传统的乘法,而选择对数和指数函数。 几种实现利用了元编程、列表操作和高阶函数(如 `foldr` 和 `cata/hylo`)等高级概念。 作者包含了大量的测试来验证正确性,并邀请贡献新的解决方案。这篇文章突出了 Bruijn 的灵活性和表达能力,展示了一个看似简单的语言如何支持多种编程范式。 提供了一个包含所有函数和测试的可重现文件,鼓励实验和进一步探索。

相关文章

原文
Many Factorials in Bruijn

I’m on a 16h flight to the ICFP SRC in Singapore right now, so here are many ways to calculate a factorial in bruijn, a syntactic sugar for the untyped lambda calculus using de Bruijn indices. It may be fun to view some of the programs as puzzles.

(try clicking definitions or hovering indices/abstractions!)

rosetta code)

monad blog post)

meta blog post)

math blog post)

rosetta code)

talk slides)

Here is a reproducible file of all the presented functions with tests.

Either way, I hope you learned something new. I encourage you to try something similar in your favorite (esoteric) language.

Support on Ko-fi. Subscribe on RSS. Follow on Mastodon.


联系我们 contact @ memedata.com