任何方式在do / while / let块中打印出一个变量类型? [英] Any way to print out a type of a variable in a do / while / let block?
本文介绍了任何方式在do / while / let块中打印出一个变量类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在 ghci
中打印出嵌套变量的推断类型?考虑代码,
Is there any way to print out the inferred type of a nested variable in ghci
? Consider the code,
let f = g where
g (x :: Int) = x
然后,查询 g
,例如:t f.g
会打印出 Int - > Int
。
then, it'd be nice to query the type of g
, e.g. :t f.g
would print out Int -> Int
.
推荐答案
您可以通过给出错误的类型注释并检查错误消息。
You can coax this information out by giving an appropriately wrong type annotation and checking the error message.
*Main> let f = g where g::a; g (x::Int) = x
<interactive>:1:23:
Couldn't match type `a1' with `Int -> Int'
`a1' is a rigid type variable bound by...
这篇关于任何方式在do / while / let块中打印出一个变量类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文