未定义的Show实例 [英] a Show instance for undefined
本文介绍了未定义的Show实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可以做任何事情来为一个未定义的值定义一个Show实例吗?也许有一些GHC扩展存在?我想要这样的东西:
Can anything be done to define a Show instance for an undefined value? Maybe some GHC extensions exist? I want something like this:
> print (1,undefined)
(1,"undefined")
推荐答案
根据 Haskell 2010报告,第9章< a>,评价 undefined
应该总是会导致错误:
According to the Haskell 2010 report, chapter 9, evaluating undefined
should always cause an error:
-- It is expected that compilers will recognize this and insert error
-- messages that are more appropriate to the context in which undefined
-- appears.
undefined :: a
undefined = error "Prelude.undefined"
自打印一个值包括评估它,这总会给出一个错误。
Since printing a value includes evaluating it, this will always give an error.
这篇关于未定义的Show实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文