Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ghci to find type

Tags:

haskell

ghci

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?

like image 669
egidra Avatar asked Sep 30 '12 08:09

egidra


People also ask

How do I know my Ghci type?

Note that if you are in GHCI, you can just put :type before your expression to determine the expression's type, or use :set +t to see the type of every expression in GHCI.

Which function is used to find type signature in Haskell?

We thus see that we make use of two functions here: (&&) :: Bool -> Bool -> Bool , and elem :: (Eq e, Foldable f) => e -> f e -> Bool , we here use e instead of f to avoid "name clashes" with our already defined type variable a .

How do I use Haskell Ghci?

If you have installed the Haskell Platform, open a terminal and type ghci (the name of the executable of the GHC interpreter) at the command prompt. Alternatively, if you are on Windows, you may choose WinGHCi in the Start menu. And you are presented with a prompt. The Haskell system now attentively awaits your input.

What is the difference between GHC and Ghci?

Introduction. GHCi is GHC's interactive environment, in which Haskell expressions can be interactively evaluated and programs can be interpreted.


1 Answers

Use the ghci :t command, like so:

Prelude> let x = 7 + 2
Prelude> :t x
x :: Integer
Prelude> 
like image 106
dave4420 Avatar answered Sep 21 '22 08:09

dave4420