The module TypeRep exposes the representation because a few other modules (Type, TcType, Unify, etc) work directly on its representation. However, you should not lightly pattern-match on Type; it is meant to be an abstract type. Instead, try to use functions defined by Type, TcType etc.

Views of types

Even when considering only types (not kinds, sorts, coercions) you need to know that GHC uses a single data type for types, even though there are two different "views".

The "typechecker view" (or "source view") regards the type as a Haskell type, complete with implicit parameters, class constraints, and the like. For example:

forall a. (Eq a, %x::Int) => a -> Int

The "core view" regards the type as a Core-language type, where class and implicit parameter constraints are treated as function arguments:

forall a. Eq a -> Int -> a -> Int

These two "views" are supported by a family of functions operating over that view:

The "view" functions are shallow, not deep---a view function just looks at the root of the tree representing the type. For example, part of the coreView function (compiler/types/Type.lhs) looks like this:

Invariant: if the head of a type application is a TyCon, GHC always uses the TyConApp constructor, not AppTy.
This invariant is maintained internally by 'smart constructors'.
A similar invariant applies to FunTy; TyConApp is never used with an arrow type.

Type variables

Type variables are represented by the TyVar constructor of the data type Var.

Type variables range over both types (possibly of higher kind) or coercions. You could tell the difference between these two by taking the typeKind of the kind of the type variable, and seeing if you have sort TY or CO, but for efficiency the TyVar keeps a boolean flag, and returns a function:

isCoercionVar :: TyVar -> Bool

Classifying types

GHC uses the following nomenclature for types:

Unboxed

A type is unboxed iff its representation is other than a pointer. Unboxed types are also unlifted.

Lifted

A type is lifted iff it has bottom as an element. Closures always have lifted types: i.e. any let-bound identifier in Core must have a lifted type. Operationally, a lifted object is one that can be entered. Only lifted types may be unified with a type variable.

Data

A type declared with data. Also boxed tuples.

Algebraic

An algebraic data type is a data type with one or more constructors, whether declared with data or newtype. An algebraic type is one that can be deconstructed with a case expression. "Algebraic" is NOT the same as "lifted", because unboxed tuples count as "algebraic".

Primitive

a type is primitive iff it is a built-in type that can't be expressed in Haskell.
Currently, all primitive types are unlifted, but that's not necessarily the case. (E.g. Int could be primitive.)

Some primitive types are unboxed, such as Int#, whereas some are boxed but unlifted (such as ByteArray#). The only primitive types that we classify as algebraic are the unboxed tuples.