-data InPat name
- = WildPatIn -- wild card
- | VarPatIn name -- variable
- | LitPatIn HsLit -- literal
- | LazyPatIn (InPat name) -- lazy pattern
- | AsPatIn name -- as pattern
- (InPat name)
- | ConPatIn name -- constructed type
- [InPat name]
- | ConOpPatIn (InPat name)
- name
- (InPat name)
- | ListPatIn [InPat name] -- syntactic list
- -- must have >= 1 elements
- | TuplePatIn [InPat name] -- tuple
-
- | RecPatIn name -- record
- [(name, InPat name, Bool)] -- True <=> source used punning
-
-data OutPat tyvar uvar id
- = WildPat (GenType tyvar uvar) -- wild card
-
- | VarPat id -- variable (type is in the Id)
-
- | LazyPat (OutPat tyvar uvar id) -- lazy pattern
-
- | AsPat id -- as pattern
- (OutPat tyvar uvar id)
-
- | ConPat Id -- Constructor is always an Id
- (GenType tyvar uvar) -- the type of the pattern
- [(OutPat tyvar uvar id)]
-
- | ConOpPat (OutPat tyvar uvar id) -- just a special case...
- Id
- (OutPat tyvar uvar id)
- (GenType tyvar uvar)
- | ListPat -- syntactic list
- (GenType tyvar uvar) -- the type of the elements
- [(OutPat tyvar uvar id)]
-
- | TuplePat [(OutPat tyvar uvar id)] -- tuple
- -- UnitPat is TuplePat []
-
- | RecPat Id -- record constructor
- (GenType tyvar uvar) -- the type of the pattern
- [(id, OutPat tyvar uvar id, Bool)] -- True <=> source used punning
-
- | LitPat -- Used for *non-overloaded* literal patterns:
- -- Int#, Char#, Int, Char, String, etc.
- HsLit
- (GenType tyvar uvar) -- type of pattern
-
- | NPat -- Used for *overloaded* literal patterns
- HsLit -- the literal is retained so that
- -- the desugarer can readily identify
- -- equations with identical literal-patterns
- (GenType tyvar uvar) -- type of pattern, t
- (HsExpr tyvar uvar id (OutPat tyvar uvar id))
- -- of type t -> Bool; detects match
-
- | DictPat -- Used when destructing Dictionaries with an explicit case
+type InPat id = LPat id -- No 'Out' constructors
+type OutPat id = LPat id -- No 'In' constructors
+
+type LPat id = Located (Pat id)
+
+data Pat id
+ = ------------ Simple patterns ---------------
+ WildPat PostTcType -- Wild card
+ | VarPat id -- Variable
+ | LazyPat (LPat id) -- Lazy pattern
+ | AsPat (Located id) (LPat id) -- As pattern
+ | ParPat (LPat id) -- Parenthesised pattern
+
+ ------------ Lists, tuples, arrays ---------------
+ | ListPat [LPat id] -- Syntactic list
+ PostTcType -- The type of the elements
+
+ | TuplePat [LPat id] -- Tuple
+ Boxity -- UnitPat is TuplePat []
+
+ | PArrPat [LPat id] -- Syntactic parallel array
+ PostTcType -- The type of the elements
+
+ ------------ Constructor patterns ---------------
+ | ConPatIn (Located id)
+ (HsConDetails id (LPat id))
+
+ | ConPatOut DataCon
+ (HsConDetails id (LPat 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 (Located id) -- n+k pattern
+ HsOverLit -- It'll always be an HsIntegral
+ SyntaxName -- Name of '-' (see RnEnv.lookupSyntaxName)
+
+ | NPlusKPatOut (Located id)
+ Integer
+ (HsExpr id) -- Of type t -> Bool; detects match
+ (HsExpr id) -- Of type t -> t; subtracts k
+
+
+ ------------ Generics ---------------
+ | TypePat (LHsType 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 (LPat id) -- Pattern with a type signature
+ (LHsType id)
+
+ | SigPatOut (LPat id) -- Pattern p
+ Type -- Type, t, of the whole pattern
+ (HsExpr id) -- Coercion function,
+ -- of type t -> typeof(p)
+
+ ------------ Dictionary patterns (translation only) ---------------
+ | DictPat -- Used when destructing Dictionaries with an explicit case