为什么此函数似乎隐藏其嵌入式异常? [英] Why does this function seem to hide its embedded exception?

查看:73
本文介绍了为什么此函数似乎隐藏其嵌入式异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在评论另一个问题时,我发现参照透明性明显中断。在ghci中:

While commenting on another question, I discovered an apparent break in referential transparency. In 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-目前我的计算机上尚未安装任何其他版本。)

Why isn't the first one bottom? (GHC 8.2.2 in case it matters -- I don't have any other versions installed on this machine at the moment.)

推荐答案

看起来像是跟踪#14002 。如果您这样做:

Looks like this is Trac #14002. If you do a:

> :set -fpedantic-bottoms

或定义 f 在文件中并将其加载到GHCi中,然后这两个表达式都会引发异常。

or define f in a file and load it into GHCi, then both expressions cause an exception.

该错误报告声称,在不造成性能损失的情况下很难修复。

The bug report claims it's difficult to fix without incurring a performance penalty.

这篇关于为什么此函数似乎隐藏其嵌入式异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆