2 % (c) The AQUA Project, Glasgow University, 1996-1998
4 \section[DsHsSyn]{Haskell abstract syntax---added things for desugarer}
9 #include "HsVersions.h"
11 import HsSyn ( OutPat(..), MonoBinds(..) )
12 import TcHsSyn ( TypecheckedPat,
13 TypecheckedMonoBinds )
15 import Id ( idType, Id )
17 import TysWiredIn ( mkListTy, mkTupleTy, unitTy )
18 import BasicTypes ( Boxity(..) )
19 import Panic ( panic )
22 Note: If @outPatType@ doesn't bear a strong resemblance to @exprType@,
23 then something is wrong.
25 outPatType :: TypecheckedPat -> Type
27 outPatType (WildPat ty) = ty
28 outPatType (VarPat var) = idType var
29 outPatType (LazyPat pat) = outPatType pat
30 outPatType (AsPat var pat) = idType var
31 outPatType (ConPat _ ty _ _ _) = ty
32 outPatType (ListPat ty _) = mkListTy ty
33 outPatType (TuplePat pats box) = mkTupleTy box (length pats) (map outPatType pats)
34 outPatType (RecPat _ ty _ _ _) = ty
35 outPatType (LitPat lit ty) = ty
36 outPatType (NPat lit ty _) = ty
37 outPatType (NPlusKPat _ _ ty _ _) = ty
38 outPatType (DictPat ds ms) = case (length ds_ms) of
40 1 -> idType (head ds_ms)
41 n -> mkTupleTy Boxed n (map idType ds_ms)
47 Nota bene: @DsBinds@ relies on the fact that at least for simple
48 tuple patterns @collectTypedPatBinders@ returns the binders in
49 the same order as they appear in the tuple.
51 @collectTypedBinders@ and @collectedTypedPatBinders@ are the exportees.
54 collectTypedMonoBinders :: TypecheckedMonoBinds -> [Id]
55 collectTypedMonoBinders EmptyMonoBinds = []
56 collectTypedMonoBinders (PatMonoBind pat _ _) = collectTypedPatBinders pat
57 collectTypedMonoBinders (FunMonoBind f _ _ _) = [f]
58 collectTypedMonoBinders (VarMonoBind v _) = [v]
59 collectTypedMonoBinders (CoreMonoBind v _) = [v]
60 collectTypedMonoBinders (AndMonoBinds bs1 bs2)
61 = collectTypedMonoBinders bs1 ++ collectTypedMonoBinders bs2
62 collectTypedMonoBinders (AbsBinds _ _ exports _ _)
63 = [global | (_, global, local) <- exports]
65 collectTypedPatBinders :: TypecheckedPat -> [Id]
66 collectTypedPatBinders (VarPat var) = [var]
67 collectTypedPatBinders (LazyPat pat) = collectTypedPatBinders pat
68 collectTypedPatBinders (AsPat a pat) = a : collectTypedPatBinders pat
69 collectTypedPatBinders (ConPat _ _ _ _ pats) = concat (map collectTypedPatBinders pats)
70 collectTypedPatBinders (ListPat t pats) = concat (map collectTypedPatBinders pats)
71 collectTypedPatBinders (TuplePat pats _) = concat (map collectTypedPatBinders pats)
72 collectTypedPatBinders (RecPat _ _ _ _ fields) = concat (map (\ (f,pat,_) -> collectTypedPatBinders pat)
74 collectTypedPatBinders (DictPat ds ms) = ds ++ ms
75 collectTypedPatBinders (NPlusKPat var _ _ _ _) = [var]
76 collectTypedPatBinders any_other_pat = [ {-no binders-} ]