代码之家  ›  专栏  ›  技术社区  ›  Daniel Wagner

为什么这个函数似乎隐藏了其嵌入的异常?

  •  12
  • Daniel Wagner  · 技术社区  · 6 年前

    在评论时 another question 我发现引用透明性有明显的突破。在GHCI中:

    > f g h = g `seq` h `seq` \x -> g (h x)
    > seq (f undefined id) ()
    ()
    > seq (undefined `seq` id `seq` \x -> undefined (id x)) ()
    *** Exception: Prelude.undefined
    CallStack (from HasCallStack):
      error, called at libraries/base/GHC/Err.hs:79:14 in base:GHC.Err
      undefined, called at <interactive>:3:14 in interactive:Ghci9
    

    为什么第一个不是底部的?(GHC 8.2.2如果重要的话——我现在没有在这台机器上安装任何其他版本。)

    1 回复  |  直到 6 年前
        1
  •  7
  •   K. A. Buhr    6 年前

    Trac #14002

    > :set -fpedantic-bottoms
    

    或者定义 f 在一个文件中并将其加载到ghci中,然后这两个表达式都会导致异常。

    这个bug报告声称在不造成性能损失的情况下很难修复。