In Haskell,
- Every expression has a type.
- The type of every expression is known at compile time (static type system).
- The type of an expression is inferred, and need not be explicitly mentioned (type inference).
- Explicit types are always denoted with the first letter in capital case.
In GHCI use :t followed by an expression to fetch the type of the expression.
ghci> :t 'a'
'a' :: Char:: is read as ‘has type of’.
Unlike lists, each tuple has its own type.
- ghci> :t (True, 'a')
- (True, 'a') :: (Bool, Char)Common types
Intbounded, but more efficient.Integerunbounded, but less efficient.
code
for(int i = 0; i < k; i ++){
cout << i;
}