本文介绍了GHCi能告诉我一个本地Haskell函数的类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能查询ghci是否为其他函数内的函数推断的类型?
这是一个快速和丑陋的黑客攻击,但我通常做的只是以错误的方式使用该函数,并阅读错误消息:
inc x = x + 1 其中f(y,z)= y + z g = f :: CharGHCi输出:
无法匹配预期的类型'Char'与推断类型`(t,t) - > t'在表达式中:f :: Char尽管这样会遗漏掉上下文 Num t => ,这通常会为我提供足够的信息以继续。
Is it possible to query the ghci for the type it inferred for a function inside another function?
解决方案This is a quick and ugly hack, but what I usually do is just use the function in the wrong way and read the error message:
inc x = x + 1 where f (y, z) = y + z g = f :: CharGHCi output:
Couldn't match expected type `Char' against inferred type `(t, t) -> t' In the expression: f :: CharAlthough this leaves out the context Num t =>, this usually does provide me with enough information to continue.
更多推荐
GHCi能告诉我一个本地Haskell函数的类型吗?
发布评论