-Patterns come in distinct before- and after-typechecking flavo(u)rs.
-\begin{code}
-data InPat name
- = WildPatIn -- wild card
- | VarPatIn name -- variable
- | LitPatIn HsLit -- literal
- | LazyPatIn (InPat name) -- lazy pattern
- | AsPatIn name -- as pattern
- (InPat name)
- | SigPatIn (InPat name)
- (HsType name)
- | ConPatIn name -- constructed type
- [InPat name]
- | ConOpPatIn (InPat name)
- name
- Fixity -- c.f. OpApp in HsExpr
- (InPat name)
-
- | NPlusKPatIn name -- n+k pattern
- HsLit
-
- -- We preserve prefix negation and parenthesis for the precedence parser.
-
- | NegPatIn (InPat name) -- negated pattern
- | ParPatIn (InPat name) -- parenthesised pattern
-
- | ListPatIn [InPat name] -- syntactic list
- -- must have >= 1 elements
- | TuplePatIn [InPat name] Bool -- tuple (boxed?)
-
- | RecPatIn name -- record
- [(name, InPat name, Bool)] -- True <=> source used punning
-
-data OutPat id
- = WildPat Type -- wild card
- | VarPat id -- variable (type is in the Id)
- | LazyPat (OutPat id) -- lazy pattern
- | AsPat id -- as pattern
- (OutPat id)
-
- | ListPat -- syntactic list
- Type -- the type of the elements
- [OutPat id]
-
- | TuplePat [OutPat id] -- tuple
- Bool -- boxed?
- -- UnitPat is TuplePat []
-
- | ConPat DataCon
- Type -- the type of the pattern
- [TyVar] -- Existentially bound type variables
- [id] -- Ditto dictionaries
- [OutPat id]
-
- -- ConOpPats are only used on the input side
-
- | RecPat DataCon -- record constructor
- Type -- the type of the pattern
- [TyVar] -- Existentially bound type variables
- [id] -- Ditto dictionaries
- [(Id, OutPat id, Bool)] -- True <=> source used punning
-
- | LitPat -- Used for *non-overloaded* literal patterns:
- -- Int#, Char#, Int, Char, String, etc.
- HsLit
- Type -- 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
- Type -- type of pattern, t
- (HsExpr id (OutPat id))
- -- of type t -> Bool; detects match
-
- | NPlusKPat id
- HsLit -- Same reason as for LitPat
- -- (This could be an Integer, but then
- -- it's harder to partitionEqnsByLit
- -- in the desugarer.)
- Type -- Type of pattern, t
- (HsExpr id (OutPat id)) -- Of type t -> Bool; detects match
- (HsExpr id (OutPat id)) -- Of type t -> t; subtracts k