haskell - 为什么管道定义内部功能

标签 haskell ghc haskell-pipes

我在看 pipes库源代码,例如 Core module我不明白为什么作者到处使用这样定义函数的模式:

runEffect = go
  where
    go p = ...

或者:
pull = go
  where
    go a' = ...

或者:
reflect = go
  where
    go p = ...

这是启用某些优化的技巧吗?我觉得它很难看,如果它是一些优化技巧,我真的希望编译器可以在没有这样的事情的情况下做到这一点。但也许还有其他原因?

最佳答案

GHC 只会内联非递归函数,并且仅当从句法的角度“完全应用”它们时(即在调用站点,它们被应用于定义左侧出现的参数数量)。

在您发布的示例中没有参数,但是定义可能是递归的并且不会被内联。执行此转换可能允许在调用站点内联和专门化定义(对于 m 等的具体类型)。

Is this some trick to enable some optimizations? I find it ugly, if it's some optimization trick I really wish the compiler could do it without things like that.



是的,它 super 蹩脚。

关于haskell - 为什么管道定义内部功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31168743/

相关文章:

haskell - 使用 `newtype` 包装其他类型

haskell - GHC 管道 : Core, STG - AST 还是文本?

haskell - 如何将外部导出函数的参数传递到管道中?

haskell - Pipes (Haskell lib) - 具有不同状态 monad 的管道

xml - 用于创建 xml 请求的 zipper ?

haskell - 如何将 MonadThrow 实例添加到 Warp 服务器中的 ResourceT Monad Transformer

haskell - dataToTag 参数的严格性

haskell - 使用 `deriving` 关键字分析 GHC 生成的函数

haskell - Maybe 从 Maybes 构建数据