简体   繁体   English

为什么Text.Show.Functions只返回 <function> ?

[英]Why does Text.Show.Functions only return <function>?

The standard package to show functions only returns a constant string: 显示函数的标准包只返回一个常量字符串:

λ> :m +Text.Show.Functions 
λ> show (+1)
"<function>"

GHCi's :type command is much more useful: GHCi :type命令更有用:

λ> :t (+1)
(+1) :: Num a => a -> a

Is it impossible to get such a level of detail at runtime? 在运行时是否无法获得如此高水平的细节? Does the compilation process leave any kind of information at all about functions, except for them being functions? 编译过程是否会留下关于函数的任何信息,除非它们是函数?

Not exactly the same level of details, but you can use typeOf from Data.Typeable : 不完全相同的细节级别,但您可以使用Data.Typeable中的 typeOf

Prelude> import Data.Typeable
Prelude Data.Typeable> typeOf (+1)
Integer -> Integer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM