我可以“分解”类型签名吗?

Can I “factorize” a type signature?

假设我想要一个 [[a]] -> [[b]] -> [[(a, b)]] 类型的函数。我确定我能想出办法,但很有可能,它不会像 zipWith zip 那样干净,它也有那种类型。

将此类型签名输入 Hoogle 会给我一些函数来填补这个角色,但它们来自 leancheckextrapolate 包,我不想这样做无缘无故拖入我的项目。

鉴于您可以通过等式推理计算函数组合,我想知道这个过程是否存在逆过程:有没有一种方法可以“分解”复杂类型签名并减少它归结为最简单的函数组合?

感谢 DanielWagner 和 Willem Van Onsem,他们在评论中回答了我的问题。我以为是某种 category-theory 因式分解结果只是代码生成。

exference 正是我想要的。来自文档:

Type inference takes an expression and tells you its type. This process can be inversed: We recursively create random expression trees while checking that they -so far- match a given input type. At each step we do the backwards step of the inference algorithm step. If you are lucky, this search yields one or more expressions.


djinn also does code generation from type expressions, but supports less types, and has little documentation。但是,与 exference 不同,它保证总是终止。

对于emacs用户来说,似乎.


还有 Djest,由 luqui 开发,它介于 Quickcheck 和以前的工具之间。它允许您输入几组输入和输出,程序将尝试组成满足它们的函数。

感谢所有做出贡献并让我发现这些软件包的人。