2 % (c) The AQUA Project, Glasgow University, 1996
4 \section[DsHsSyn]{Haskell abstract syntax---added things for desugarer}
7 #include "HsVersions.h"
13 import HsSyn ( OutPat(..), HsBinds(..), Bind(..), MonoBinds(..),
14 Sig, HsExpr, GRHSsAndBinds, Match, HsLit )
15 import TcHsSyn ( TypecheckedPat(..), TypecheckedBind(..),
16 TypecheckedMonoBinds(..) )
19 import PrelInfo ( mkListTy, mkTupleTy, unitTy )
23 Note: If @outPatType@ doesn't bear a strong resemblance to @coreExprType@,
24 then something is wrong.
26 outPatType :: TypecheckedPat -> Type
28 outPatType (WildPat ty) = ty
29 outPatType (VarPat var) = idType var
30 outPatType (LazyPat pat) = outPatType pat
31 outPatType (AsPat var pat) = idType var
32 outPatType (ConPat _ ty _) = ty
33 outPatType (ConOpPat _ _ _ ty) = ty
34 outPatType (ListPat ty _) = mkListTy ty
35 outPatType (TuplePat pats) = mkTupleTy (length pats) (map outPatType pats)
36 outPatType (RecPat _ ty _) = ty
37 outPatType (LitPat lit ty) = ty
38 outPatType (NPat lit ty _) = ty
39 outPatType (DictPat ds ms) = case (length ds + length ms) of
41 1 -> idType (head (ds ++ ms))
42 n -> mkTupleTy n (map idType (ds ++ ms))
46 Nota bene: DsBinds relies on the fact that at least for simple
47 tuple patterns @collectTypedPatBinders@ returns the binders in
48 the same order as they appear in the tuple.
50 collectTypedBinders and collectedTypedPatBinders are the exportees.
53 collectTypedBinders :: TypecheckedBind -> [Id]
54 collectTypedBinders EmptyBind = []
55 collectTypedBinders (NonRecBind bs) = collectTypedMonoBinders bs
56 collectTypedBinders (RecBind bs) = collectTypedMonoBinders bs
58 collectTypedMonoBinders :: TypecheckedMonoBinds -> [Id]
59 collectTypedMonoBinders EmptyMonoBinds = []
60 collectTypedMonoBinders (PatMonoBind pat _ _) = collectTypedPatBinders pat
61 collectTypedMonoBinders (FunMonoBind f _ _ _) = [f]
62 collectTypedMonoBinders (VarMonoBind v _) = [v]
63 collectTypedMonoBinders (AndMonoBinds bs1 bs2)
64 = collectTypedMonoBinders bs1 ++ collectTypedMonoBinders bs2
66 collectTypedPatBinders :: TypecheckedPat -> [Id]
67 collectTypedPatBinders (VarPat var) = [var]
68 collectTypedPatBinders (LazyPat pat) = collectTypedPatBinders pat
69 collectTypedPatBinders (AsPat a pat) = a : collectTypedPatBinders pat
70 collectTypedPatBinders (ConPat _ _ pats) = concat (map collectTypedPatBinders pats)
71 collectTypedPatBinders (ConOpPat p1 _ p2 _) = collectTypedPatBinders p1 ++ collectTypedPatBinders p2
72 collectTypedPatBinders (ListPat t pats) = concat (map collectTypedPatBinders pats)
73 collectTypedPatBinders (TuplePat pats) = concat (map collectTypedPatBinders pats)
74 collectTypedPatBinders (DictPat ds ms) = ds ++ ms
75 collectTypedPatBinders any_other_pat = [ {-no binders-} ]