+\begin{code}
+type InPat id = Pat id -- No 'Out' constructors
+type OutPat id = Pat id -- No 'In' constructors
+
+data Pat id
+ = ------------ Simple patterns ---------------
+ WildPat PostTcType -- Wild card
+ | VarPat id -- Variable
+ | LazyPat (Pat id) -- Lazy pattern
+ | AsPat id (Pat id) -- As pattern
+ | ParPat (Pat id) -- Parenthesised pattern
+
+ ------------ Lists, tuples, arrays ---------------
+ | ListPat [Pat id] -- Syntactic list
+ PostTcType -- The type of the elements
+
+ | TuplePat [Pat id] -- Tuple
+ Boxity -- UnitPat is TuplePat []
+
+ | PArrPat [Pat id] -- Syntactic parallel array
+ PostTcType -- The type of the elements
+
+ ------------ Constructor patterns ---------------
+ | ConPatIn id
+ (HsConDetails id (Pat id))
+
+ | ConPatOut DataCon
+ (HsConDetails id (Pat id))
+ Type -- The type of the pattern
+ [TyVar] -- Existentially bound type variables
+ [id] -- Ditto dictionaries
+
+ ------------ Literal and n+k patterns ---------------
+ | LitPat HsLit -- Used for *non-overloaded* literal patterns:
+ -- Int#, Char#, Int, Char, String, etc.
+
+ | NPatIn HsOverLit -- Always positive
+ (Maybe SyntaxName) -- Just (Name of 'negate') for negative
+ -- patterns, Nothing otherwise
+
+ | NPatOut HsLit -- Used for literal patterns where there's an equality function to call
+ -- The literal is retained so that the desugarer can readily identify
+ -- equations with identical literal-patterns
+ -- Always HsInteger, HsRat or HsString.
+ -- Always HsInteger, HsRat or HsString.
+ -- *Unlike* NPatIn, for negative literals, the
+ -- literal is acutally negative!
+ Type -- Type of pattern, t
+ (HsExpr id) -- Of type t -> Bool; detects match
+
+ | NPlusKPatIn id -- n+k pattern
+ HsOverLit -- It'll always be an HsIntegral
+ SyntaxName -- Name of '-' (see RnEnv.lookupSyntaxName)
+
+ | NPlusKPatOut id
+ Integer
+ (HsExpr id) -- Of type t -> Bool; detects match
+ (HsExpr id) -- Of type t -> t; subtracts k
+
+
+ ------------ Generics ---------------
+ | TypePat (HsType id) -- Type pattern for generic definitions
+ -- e.g f{| a+b |} = ...
+ -- These show up only in class declarations,
+ -- and should be a top-level pattern
+
+ ------------ Pattern type signatures ---------------
+ | SigPatIn (Pat id) -- Pattern with a type signature
+ (HsType id)
+
+ | SigPatOut (Pat id) -- Pattern p
+ Type -- Type, t, of the whole pattern
+ (HsExpr id) -- Coercion function,
+ -- of type t -> typeof(p)
+
+ ------------ Dictionary patterns (translation only) ---------------