开发者

Can GHCi tell me the type of a local Haskell function?

开发者 https://www.devze.com 2022-12-18 11:09 出处:网络
Is it possible to query the ghci for the type i开发者_Python百科t 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 w

Is it possible to query the ghci for the type i开发者_Python百科t 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.


You might try doing it by setting a breakpoint on it, so the function is in scope from the debugger.

Also I think that EclipseFP can tell you the types of things when you mouse over them, at least some of the time.


With GHC 7.8+, just append `asTypeOf` _ to the expression.

See Find out the type of an expression/function with typed holes for a detailed explanation.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号