GHCi能告诉我一个本地Haskell函数的类型吗? [英] Can GHCi tell me the type of a local Haskell function?

查看:74
本文介绍了GHCi能告诉我一个本地Haskell函数的类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能查询ghci是否为其他函数内的函数推断的类型?

这是一个快速和丑陋的黑客攻击,但我通常做的只是以错误的方式使用该函数,并阅读错误消息:

  inc x = x + 1 
其中
f(y,z)= y + z
g = f :: Char

GHCi输出:

 无法匹配预期的类型'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 :: Char

GHCi output:

Couldn't match expected type `Char'
       against inferred type `(t, t) -> t'
In the expression: f :: Char

Although this leaves out the context Num t =>, this usually does provide me with enough information to continue.

这篇关于GHCi能告诉我一个本地Haskell函数的类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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