by necrobious · 15y ago · 0 comments
Yup, just like you do in most statically typed languages.
(* Standard ML of New Jersey v110.72 [built: Sun May 16 15:16:12 2010] *)
- 5;
val it = 5 : int
(* Objective Caml version 3.11.2 *)
# 5;;
- : int = 5
// D programming language
void main(string[] args){
writefln(typeid(typeof(5)));
}
// Output: int
// C# 4.0
var n = 5; // int
// Go programming language
var n = 5 // int
// Welcome to Scala version 2.7.7final (OpenJDK 64-Bit Server VM, Java 1.6.0_20).
scala> 5;
res0: Int = 5
// C++
#include <iostream>
#include <typeinfo>
int main(){
cout << typeid(5).name() << endl;
return 0;
}
// Output: i
I see... // GHCi, version 6.12.3: http://www.haskell.org/ghc/
Prelude> :set +t
Prelude> 5
5
it :: Integer :set +t GHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for help
Prelude> :?
...
Options for ':set' and ':unset':
+t print type after evaluation
Of course it isn't necessary at all. $ ghci
GHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> 5
5
Prelude> :t it
it :: Integer
Try it at home.