egidra
egidra

Reputation: 9087

Using ghci to find type

When I do something simple in ghci, like the following:

let x = 7 + 2

I expect ghci to give a response of the type that x holds, like:

x :: Integer

When I run ghci, I do not get that the above line. How do I get that response?

Upvotes: 12

Views: 11697

Answers (3)

Taneb
Taneb

Reputation: 198

To find the type of something in GHCi, you can use the :type command, or (as is much more common), the abbreviated :t. With this, you can do something like:

Prelude> let x = 7 + 2
Prelude> :t x
x :: Integer

Upvotes: 9

Matvey Aksenov
Matvey Aksenov

Reputation: 3900

To show types automatically use :set +t:

μ> :set +t
μ> let x = 7 + 2
x :: Integer
μ>

Upvotes: 32

dave4420
dave4420

Reputation: 47062

Use the ghci :t command, like so:

Prelude> let x = 7 + 2
Prelude> :t x
x :: Integer
Prelude> 

Upvotes: 14

Related Questions