Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Is it possible to query the ghci for the type it inferred for a function inside another function?

like image 410
user125661 Avatar asked Jan 24 '10 19:01

user125661


2 Answers

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.

like image 159
Tom Lokhorst Avatar answered Oct 29 '22 23:10

Tom Lokhorst


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.

like image 30
Paul Johnson Avatar answered Oct 29 '22 23:10

Paul Johnson