As you’re writing Haskell and working with types, there are two ghci commands that will be immensely helpful to you. The :type command, which we often abbreviate :t , will give you the type of an arbitrary Haskell expression, and the :info command, which is often abbreviated :i , will give you a bit more information, but not for an arbitrary expression. :info will only work for functions that you’ve loaded in from a module or source file. Let’s look at a few examples of using :type to get the type information from some expressions. You won’t understand many of the types here yet, but as you work your way through the chapter, you’ll get a chance to use all of the features individually, and by the end, you’ll be able to fluidly read and understand these sorts of type signatures.
| | λ x = 1 :: Int |
| | λ : type x |
| | x :: Int |
| | λ : type "Hello, World" |
| | "Hello, World" :: [ Char ] |
| | λ : type ( True , False ) |
| | ( True , False ) :: ( Bool , Bool ) |
| | λ : type (.) |
| | (.) :: (b -> c) -> (a -> b) -> a -> c |
| | λ : type (1 + ) |
| | (1 + ) :: Num a => a -> a |
| | λ : type \ f -> map (f . f) |
| | \ f -> map (f . f) :: (b -> b) -> [b] -> [b] |
| | λ : type map (+ 5) |
| | map (+ 5) :: Num b => [b] -> [b] |
| | λ : type \ f -> zipWith f [1..10] [10..1] |
| | \ f -> zipWith f [1..10] [10..1] |
| | :: ( Num a, Num b, Enum a, Enum b) => (a -> b -> c) -> [c] |
| | λ |