[project @ 2002-06-18 08:05:44 by simonpj]
[ghc-hetmet.git] / ghc / compiler / hsSyn / HsTypes.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
3 %
4 \section[HsTypes]{Abstract syntax: user-defined types}
5
6 \begin{code}
7 module HsTypes (
8           HsType(..), HsTyVarBndr(..), HsTyOp(..),
9         , HsContext, HsPred(..)
10         , HsTupCon(..), hsTupParens, mkHsTupCon,
11         , hsUsOnce, hsUsMany
12
13         , mkHsForAllTy, mkHsDictTy, mkHsIParamTy
14         , hsTyVarName, hsTyVarNames, replaceTyVarName
15         , getHsInstHead
16         
17         -- Type place holder
18         , PostTcType, placeHolderType,
19
20         -- Name place holder
21         , SyntaxName, placeHolderName,
22
23         -- Printing
24         , pprParendHsType, pprHsForAll, pprHsContext, ppr_hs_context, pprHsTyVarBndr
25
26         -- Equality over Hs things
27         , EqHsEnv, emptyEqHsEnv, extendEqHsEnv,
28         , eqWithHsTyVars, eq_hsVar, eq_hsVars, eq_hsTyVars, eq_hsType, eq_hsContext, eqListBy
29
30         -- Converting from Type to HsType
31         , toHsType, toHsTyVar, toHsTyVars, toHsContext, toHsFDs
32     ) where
33
34 #include "HsVersions.h"
35
36 import Class            ( FunDep )
37 import TcType           ( Type, Kind, ThetaType, SourceType(..), 
38                           tcSplitSigmaTy, liftedTypeKind, eqKind, tcEqType
39                         )
40 import TypeRep          ( Type(..), TyNote(..) )        -- toHsType sees the representation
41 import TyCon            ( isTupleTyCon, tupleTyConBoxity, tyConArity, isNewTyCon, getSynTyConDefn )
42 import RdrName          ( RdrName, mkUnqual )
43 import Name             ( Name, getName, mkInternalName )
44 import OccName          ( NameSpace, mkVarOcc, tvName )
45 import Var              ( TyVar, tyVarKind )
46 import Subst            ( substTyWith )
47 import PprType          ( {- instance Outputable Kind -}, pprParendKind, pprKind )
48 import BasicTypes       ( Boxity(..), Arity, IPName, tupleParens )
49 import PrelNames        ( mkTupConRdrName, listTyConKey, parrTyConKey,
50                           usOnceTyConKey, usManyTyConKey, hasKey, unboundKey,
51                           usOnceTyConName, usManyTyConName )
52 import SrcLoc           ( builtinSrcLoc )
53 import Util             ( eqListBy, lengthIs )
54 import FiniteMap
55 import Outputable
56 \end{code}
57
58
59 %************************************************************************
60 %*                                                                      *
61 \subsection{Annotating the syntax}
62 %*                                                                      *
63 %************************************************************************
64
65 \begin{code}
66 type PostTcType = Type          -- Used for slots in the abstract syntax
67                                 -- where we want to keep slot for a type
68                                 -- to be added by the type checker...but
69                                 -- before typechecking it's just bogus
70
71 placeHolderType :: PostTcType   -- Used before typechecking
72 placeHolderType  = panic "Evaluated the place holder for a PostTcType"
73
74
75 type SyntaxName = Name          -- These names are filled in by the renamer
76                                 -- Before then they are a placeHolderName (so that
77                                 --      we can still print the HsSyn)
78                                 -- They correspond to "rebindable syntax";
79                                 -- See RnEnv.lookupSyntaxName
80
81 placeHolderName :: SyntaxName
82 placeHolderName = mkInternalName unboundKey 
83                         (mkVarOcc FSLIT("syntaxPlaceHolder")) 
84                         builtinSrcLoc
85 \end{code}
86
87
88 %************************************************************************
89 %*                                                                      *
90 \subsection{Data types}
91 %*                                                                      *
92 %************************************************************************
93
94 This is the syntax for types as seen in type signatures.
95
96 \begin{code}
97 type HsContext name = [HsPred name]
98
99 data HsPred name = HsClassP name [HsType name]
100                  | HsIParam (IPName name) (HsType name)
101
102 data HsType name
103   = HsForAllTy  (Maybe [HsTyVarBndr name])      -- Nothing for implicitly quantified signatures
104                 (HsContext name)
105                 (HsType name)
106
107   | HsTyVar             name            -- Type variable or type constructor
108
109   | HsAppTy             (HsType name)
110                         (HsType name)
111
112   | HsFunTy             (HsType name)   -- function type
113                         (HsType name)
114
115   | HsListTy            (HsType name)   -- Element type
116
117   | HsPArrTy            (HsType name)   -- Elem. type of parallel array: [:t:]
118
119   | HsTupleTy           (HsTupCon name)
120                         [HsType name]   -- Element types (length gives arity)
121
122   | HsOpTy              (HsType name) (HsTyOp name) (HsType name)
123
124   | HsParTy             (HsType name)   
125         -- Parenthesis preserved for the precedence re-arrangement in RnTypes
126         -- It's important that a * (b + c) doesn't get rearranged to (a*b) + c!
127         -- 
128         -- However, NB that toHsType doesn't add HsParTys (in an effort to keep
129         -- interface files smaller), so when printing a HsType we may need to
130         -- add parens.  
131
132   | HsNumTy             Integer         -- Generics only
133
134   -- these next two are only used in interfaces
135   | HsPredTy            (HsPred name)
136
137   | HsKindSig           (HsType name)   -- (ty :: kind)
138                         Kind            -- A type with a kind signature
139
140
141 data HsTyOp name = HsArrow | HsTyOp name
142         -- Function arrows from *source* get read in as HsOpTy t1 HsArrow t2
143         -- But when we generate or parse interface files, we use HsFunTy.
144         -- This keeps interfaces a bit smaller, because there are a lot of arrows
145
146 -----------------------
147 hsUsOnce, hsUsMany :: HsType RdrName
148 hsUsOnce = HsTyVar (mkUnqual tvName FSLIT("."))  -- deep magic
149 hsUsMany = HsTyVar (mkUnqual tvName FSLIT("!"))  -- deep magic
150
151 hsUsOnce_Name, hsUsMany_Name :: HsType Name
152 hsUsOnce_Name = HsTyVar usOnceTyConName
153 hsUsMany_Name = HsTyVar usManyTyConName
154
155 -----------------------
156 data HsTupCon name = HsTupCon name Boxity Arity
157
158 instance Eq name => Eq (HsTupCon name) where
159   (HsTupCon _ b1 a1) == (HsTupCon _ b2 a2) = b1==b2 && a1==a2
160    
161 mkHsTupCon :: NameSpace -> Boxity -> [a] -> HsTupCon RdrName
162 mkHsTupCon space boxity args = HsTupCon (mkTupConRdrName space boxity arity) boxity arity
163                              where
164                                arity = length args
165
166 hsTupParens :: HsTupCon name -> SDoc -> SDoc
167 hsTupParens (HsTupCon _ b _) p = tupleParens b p
168
169 -----------------------
170 -- Combine adjacent for-alls. 
171 -- The following awkward situation can happen otherwise:
172 --      f :: forall a. ((Num a) => Int)
173 -- might generate HsForAll (Just [a]) [] (HsForAll Nothing [Num a] t)
174 -- Then a isn't discovered as ambiguous, and we abstract the AbsBinds wrt []
175 -- but the export list abstracts f wrt [a].  Disaster.
176 --
177 -- A valid type must have one for-all at the top of the type, or of the fn arg types
178
179 mkHsForAllTy mtvs []   ty = mk_forall_ty mtvs ty
180 mkHsForAllTy mtvs ctxt ty = HsForAllTy mtvs ctxt ty
181
182 -- mk_forall_ty makes a pure for-all type (no context)
183 mk_forall_ty (Just []) ty                         = ty  -- Explicit for-all with no tyvars
184 mk_forall_ty mtvs1     (HsParTy ty)               = mk_forall_ty mtvs1 ty
185 mk_forall_ty mtvs1     (HsForAllTy mtvs2 ctxt ty) = mkHsForAllTy (mtvs1 `plus` mtvs2) ctxt ty
186 mk_forall_ty mtvs1     ty                         = HsForAllTy mtvs1 [] ty
187
188 mtvs1       `plus` Nothing     = mtvs1
189 Nothing     `plus` mtvs2       = mtvs2 
190 (Just tvs1) `plus` (Just tvs2) = Just (tvs1 ++ tvs2)
191
192 mkHsDictTy cls tys = HsPredTy (HsClassP cls tys)
193 mkHsIParamTy v ty  = HsPredTy (HsIParam v ty)
194
195 data HsTyVarBndr name
196   = UserTyVar name
197   | IfaceTyVar name Kind
198         -- *** NOTA BENE *** A "monotype" in a pragma can have
199         -- for-alls in it, (mostly to do with dictionaries).  These
200         -- must be explicitly Kinded.
201
202 hsTyVarName (UserTyVar n)    = n
203 hsTyVarName (IfaceTyVar n _) = n
204
205 hsTyVarNames tvs = map hsTyVarName tvs
206
207 replaceTyVarName :: HsTyVarBndr name1 -> name2 -> HsTyVarBndr name2
208 replaceTyVarName (UserTyVar n)    n' = UserTyVar n'
209 replaceTyVarName (IfaceTyVar n k) n' = IfaceTyVar n' k
210 \end{code}
211
212
213 \begin{code}
214 getHsInstHead :: HsType name -> ([HsTyVarBndr name], (name, [HsType name]))
215         -- Split up an instance decl type, returning the 'head' part
216
217 -- In interface fiels, the type of the decl is held like this:
218 --      forall a. Foo a -> Baz (T a)
219 -- so we have to strip off function argument types,
220 -- as well as the bit before the '=>' (which is always 
221 -- empty in interface files)
222 --
223 -- The parser ensures the type will have the right shape.
224 -- (e.g. see ParseUtil.checkInstType)
225
226 getHsInstHead  (HsForAllTy (Just tvs) _ tau) = (tvs, get_head1 tau)
227 getHsInstHead  tau                           = ([],  get_head1 tau)
228
229 get_head1 (HsFunTy _ ty)                = get_head1 ty
230 get_head1 (HsPredTy (HsClassP cls tys)) = (cls,tys)
231 \end{code}
232
233
234 %************************************************************************
235 %*                                                                      *
236 \subsection{Pretty printing}
237 %*                                                                      *
238 %************************************************************************
239
240 NB: these types get printed into interface files, so 
241     don't change the printing format lightly
242
243 \begin{code}
244 instance (Outputable name) => Outputable (HsType name) where
245     ppr ty = pprHsType ty
246
247 instance (Outputable name) => Outputable (HsTyOp name) where
248     ppr HsArrow    = ftext FSLIT("->")
249     ppr (HsTyOp n) = ppr n
250
251 instance (Outputable name) => Outputable (HsTyVarBndr name) where
252     ppr (UserTyVar name)       = ppr name
253     ppr (IfaceTyVar name kind) = pprHsTyVarBndr name kind
254
255 instance Outputable name => Outputable (HsPred name) where
256     ppr (HsClassP clas tys) = ppr clas <+> hsep (map pprParendHsType tys)
257     ppr (HsIParam n ty)    = hsep [ppr n, dcolon, ppr ty]
258
259 pprHsTyVarBndr :: Outputable name => name -> Kind -> SDoc
260 pprHsTyVarBndr name kind | kind `eqKind` liftedTypeKind = ppr name
261                          | otherwise                    = hsep [ppr name, dcolon, pprParendKind kind]
262
263 pprHsForAll []  []  = empty
264 pprHsForAll tvs cxt 
265         -- This printer is used for both interface files and
266         -- printing user types in error messages; and alas the
267         -- two use slightly different syntax.  Ah well.
268   = getPprStyle $ \ sty ->
269     if userStyle sty then
270         ptext SLIT("forall") <+> interppSP tvs <> dot <+> 
271               -- **! ToDo: want to hide uvars from user, but not enough info
272               -- in a HsTyVarBndr name (see PprType).  KSW 2000-10.
273         pprHsContext cxt
274     else        -- Used in interfaces
275         ptext SLIT("__forall") <+> interppSP tvs <+> 
276         ppr_hs_context cxt <+> ptext SLIT("=>")
277
278 pprHsContext :: (Outputable name) => HsContext name -> SDoc
279 pprHsContext []  = empty
280 pprHsContext cxt = ppr_hs_context cxt <+> ptext SLIT("=>")
281
282 ppr_hs_context []  = empty
283 ppr_hs_context cxt = parens (interpp'SP cxt)
284 \end{code}
285
286 \begin{code}
287 pREC_TOP = (0 :: Int)  -- type   in ParseIface.y
288 pREC_FUN = (1 :: Int)  -- btype  in ParseIface.y
289                         -- Used for LH arg of (->)
290 pREC_OP  = (2 :: Int)   -- Used for arg of any infix operator
291                         -- (we don't keep their fixities around)
292 pREC_CON = (3 :: Int)   -- Used for arg of type applicn: 
293                         -- always parenthesise unless atomic
294
295 maybeParen :: Int       -- Precedence of context
296            -> Int       -- Precedence of top-level operator
297            -> SDoc -> SDoc      -- Wrap in parens if (ctxt >= op)
298 maybeParen ctxt_prec op_prec p | ctxt_prec >= op_prec = parens p
299                                | otherwise            = p
300         
301 -- printing works more-or-less as for Types
302
303 pprHsType, pprParendHsType :: (Outputable name) => HsType name -> SDoc
304
305 pprHsType ty       = ppr_mono_ty pREC_TOP (de_paren ty)
306 pprParendHsType ty = ppr_mono_ty pREC_CON ty
307
308 -- Remove outermost HsParTy parens before printing a type
309 de_paren (HsParTy ty) = de_paren ty
310 de_paren ty           = ty
311
312 ppr_mono_ty ctxt_prec (HsForAllTy maybe_tvs ctxt ty)
313   = maybeParen ctxt_prec pREC_FUN $
314     sep [pp_header, pprHsType ty]
315   where
316     pp_header = case maybe_tvs of
317                   Just tvs -> pprHsForAll tvs ctxt
318                   Nothing  -> pprHsContext ctxt
319
320 ppr_mono_ty ctxt_prec (HsTyVar name)      = ppr name
321 ppr_mono_ty ctxt_prec (HsFunTy ty1 ty2)   = ppr_fun_ty ctxt_prec ty1 ty2
322 ppr_mono_ty ctxt_prec (HsTupleTy con tys) = hsTupParens con (interpp'SP tys)
323 ppr_mono_ty ctxt_prec (HsKindSig ty kind) = parens (ppr_mono_ty pREC_TOP ty <+> dcolon <+> pprKind kind)
324 ppr_mono_ty ctxt_prec (HsListTy ty)       = brackets (ppr_mono_ty pREC_TOP ty)
325 ppr_mono_ty ctxt_prec (HsPArrTy ty)       = pabrackets (ppr_mono_ty pREC_TOP ty)
326 ppr_mono_ty ctxt_prec (HsPredTy pred)     = braces (ppr pred)
327 ppr_mono_ty ctxt_prec (HsNumTy n)         = integer n  -- generics only
328
329 ppr_mono_ty ctxt_prec (HsAppTy fun_ty arg_ty)
330   = maybeParen ctxt_prec pREC_CON $
331     hsep [ppr_mono_ty pREC_FUN fun_ty, ppr_mono_ty pREC_CON arg_ty]
332
333 ppr_mono_ty ctxt_prec (HsOpTy ty1 HsArrow ty2) 
334   = ppr_fun_ty ctxt_prec ty1 ty2
335
336 ppr_mono_ty ctxt_prec (HsOpTy ty1 op ty2)  
337   = maybeParen ctxt_prec pREC_OP $
338     ppr_mono_ty pREC_OP ty1 <+> ppr op <+> ppr_mono_ty pREC_OP ty2
339
340 ppr_mono_ty ctxt_prec (HsParTy ty)
341   = parens (ppr_mono_ty pREC_TOP ty)
342   -- Put the parens in where the user did
343   -- But we still use the precedence stuff to add parens because
344   --    toHsType doesn't put in any HsParTys, so we may still need them
345
346 --------------------------
347 ppr_fun_ty ctxt_prec ty1 ty2
348   = let p1 = ppr_mono_ty pREC_FUN ty1
349         p2 = ppr_mono_ty pREC_TOP ty2
350     in
351     maybeParen ctxt_prec pREC_FUN $
352     sep [p1, ptext SLIT("->") <+> p2]
353
354 --------------------------
355 pabrackets p = ptext SLIT("[:") <> p <> ptext SLIT(":]")
356 \end{code}
357
358
359 %************************************************************************
360 %*                                                                      *
361 \subsection{Converting from Type to HsType}
362 %*                                                                      *
363 %************************************************************************
364
365 @toHsType@ converts from a Type to a HsType, making the latter look as
366 user-friendly as possible.  Notably, it uses synonyms where possible, and
367 expresses overloaded functions using the '=>' context part of a HsForAllTy.
368
369 \begin{code}
370 toHsTyVar :: TyVar -> HsTyVarBndr Name
371 toHsTyVar tv = IfaceTyVar (getName tv) (tyVarKind tv)
372
373 toHsTyVars tvs = map toHsTyVar tvs
374
375 toHsType :: Type -> HsType Name
376 -- This function knows the representation of types
377 toHsType (TyVarTy tv)    = HsTyVar (getName tv)
378 toHsType (FunTy arg res) = HsFunTy (toHsType arg) (toHsType res)
379 toHsType (AppTy fun arg) = HsAppTy (toHsType fun) (toHsType arg) 
380
381 toHsType (NoteTy (SynNote ty@(TyConApp tycon tyargs)) real_ty)
382   | isNewTyCon tycon = toHsType ty
383   | syn_matches      = toHsType ty             -- Use synonyms if possible!!
384   | otherwise        = 
385 #ifdef DEBUG
386                        pprTrace "WARNING: synonym info lost in .hi file for " (ppr syn_ty) $
387 #endif
388                        toHsType real_ty              -- but drop it if not.
389   where
390     syn_matches      = ty_from_syn `tcEqType` real_ty
391     (tyvars,syn_ty)  = getSynTyConDefn tycon
392     ty_from_syn      = substTyWith tyvars tyargs syn_ty
393
394     -- We only use the type synonym in the file if this doesn't cause
395     -- us to lose important information.  This matters for usage
396     -- annotations.  It's an issue if some of the args to the synonym
397     -- have arrows in them, or if the synonym's RHS has an arrow; for
398     -- example, with nofib/real/ebnf2ps/ in Parsers.using.
399
400     -- **! It would be nice if when this test fails we could still
401     -- write the synonym in as a Note, so we don't lose the info for
402     -- error messages, but it's too much work for right now.
403     -- KSW 2000-07.
404
405 toHsType (NoteTy _ ty)         = toHsType ty
406
407 toHsType (SourceTy (NType tc tys)) = foldl HsAppTy (HsTyVar (getName tc)) (map toHsType tys)
408 toHsType (SourceTy pred)           = HsPredTy (toHsPred pred)
409
410 toHsType ty@(TyConApp tc tys)   -- Must be saturated because toHsType's arg is of kind *
411   | not saturated              = generic_case
412   | isTupleTyCon tc            = HsTupleTy (HsTupCon (getName tc) (tupleTyConBoxity tc) (tyConArity tc)) tys'
413   | tc `hasKey` listTyConKey   = HsListTy (head tys')
414   | tc `hasKey` parrTyConKey   = HsPArrTy (head tys')
415   | tc `hasKey` usOnceTyConKey = hsUsOnce_Name           -- must print !, . unqualified
416   | tc `hasKey` usManyTyConKey = hsUsMany_Name           -- must print !, . unqualified
417   | otherwise                  = generic_case
418   where
419      generic_case = foldl HsAppTy (HsTyVar (getName tc)) tys'
420      tys'         = map toHsType tys
421      saturated    = tys `lengthIs` tyConArity tc
422
423 toHsType ty@(ForAllTy _ _) = case tcSplitSigmaTy ty of
424                                 (tvs, preds, tau) -> HsForAllTy (Just (map toHsTyVar tvs))
425                                                                 (map toHsPred preds)
426                                                                 (toHsType tau)
427
428 toHsPred (ClassP cls tys) = HsClassP (getName cls) (map toHsType tys)
429 toHsPred (IParam n ty)    = HsIParam n             (toHsType ty)
430
431 toHsContext :: ThetaType -> HsContext Name
432 toHsContext theta = map toHsPred theta
433
434 toHsFDs :: [FunDep TyVar] -> [FunDep Name]
435 toHsFDs fds = [(map getName ns, map getName ms) | (ns,ms) <- fds]
436 \end{code}
437
438
439 %************************************************************************
440 %*                                                                      *
441 \subsection{Comparison}
442 %*                                                                      *
443 %************************************************************************
444
445 \begin{code}
446 instance Ord a => Eq (HsType a) where
447         -- The Ord is needed because we keep a
448         -- finite map of variables to variables
449    (==) a b = eq_hsType emptyEqHsEnv a b
450
451 instance Ord a => Eq (HsPred a) where
452    (==) a b = eq_hsPred emptyEqHsEnv a b
453
454 eqWithHsTyVars :: Ord name =>
455                   [HsTyVarBndr name] -> [HsTyVarBndr name]
456                -> (EqHsEnv name -> Bool) -> Bool
457 eqWithHsTyVars = eq_hsTyVars emptyEqHsEnv
458 \end{code}
459
460 \begin{code}
461 type EqHsEnv n = FiniteMap n n
462 -- Tracks the mapping from L-variables to R-variables
463
464 eq_hsVar :: Ord n => EqHsEnv n -> n -> n -> Bool
465 eq_hsVar env n1 n2 = case lookupFM env n1 of
466                       Just n1 -> n1 == n2
467                       Nothing -> n1 == n2
468
469 extendEqHsEnv env n1 n2 
470   | n1 == n2  = env
471   | otherwise = addToFM env n1 n2
472
473 emptyEqHsEnv :: EqHsEnv n
474 emptyEqHsEnv = emptyFM
475 \end{code}
476
477 We do define a specialised equality for these \tr{*Type} types; used
478 in checking interfaces.
479
480 \begin{code}
481 -------------------
482 eq_hsTyVars env []          []         k = k env
483 eq_hsTyVars env (tv1:tvs1) (tv2:tvs2)  k = eq_hsTyVar env tv1 tv2 $ \ env ->
484                                            eq_hsTyVars env tvs1 tvs2 k
485 eq_hsTyVars env _ _ _ = False
486
487 eq_hsTyVar env (UserTyVar v1)     (UserTyVar v2)     k = k (extendEqHsEnv env v1 v2)
488 eq_hsTyVar env (IfaceTyVar v1 k1) (IfaceTyVar v2 k2) k = k1 `eqKind` k2 && k (extendEqHsEnv env v1 v2)
489 eq_hsTyVar env _ _ _ = False
490
491 eq_hsVars env []       []       k = k env
492 eq_hsVars env (v1:bs1) (v2:bs2) k = eq_hsVars (extendEqHsEnv env v1 v2) bs1 bs2 k
493 eq_hsVars env _ _ _ = False
494 \end{code}
495
496 \begin{code}
497 -------------------
498 eq_hsTypes env = eqListBy (eq_hsType env)
499
500 -------------------
501 eq_hsType env (HsForAllTy tvs1 c1 t1) (HsForAllTy tvs2 c2 t2)
502   = eq_tvs tvs1 tvs2            $ \env ->
503     eq_hsContext env c1 c2      &&
504     eq_hsType env t1 t2
505   where
506     eq_tvs Nothing     (Just _) k    = False
507     eq_tvs Nothing     Nothing  k    = k env
508     eq_tvs (Just _)    Nothing  k    = False
509     eq_tvs (Just tvs1) (Just tvs2) k = eq_hsTyVars env tvs1 tvs2 k
510
511 eq_hsType env (HsTyVar n1) (HsTyVar n2)
512   = eq_hsVar env n1 n2
513
514 eq_hsType env (HsTupleTy c1 tys1) (HsTupleTy c2 tys2)
515   = (c1 == c2) && eq_hsTypes env tys1 tys2
516
517 eq_hsType env (HsListTy ty1) (HsListTy ty2)
518   = eq_hsType env ty1 ty2
519
520 eq_hsType env (HsKindSig ty1 k1) (HsKindSig ty2 k2)
521   = eq_hsType env ty1 ty2 && k1 `eqKind` k2
522
523 eq_hsType env (HsPArrTy ty1) (HsPArrTy ty2)
524   = eq_hsType env ty1 ty2
525
526 eq_hsType env (HsAppTy fun_ty1 arg_ty1) (HsAppTy fun_ty2 arg_ty2)
527   = eq_hsType env fun_ty1 fun_ty2 && eq_hsType env arg_ty1 arg_ty2
528
529 eq_hsType env (HsFunTy a1 b1) (HsFunTy a2 b2)
530   = eq_hsType env a1 a2 && eq_hsType env b1 b2
531
532 eq_hsType env (HsPredTy p1) (HsPredTy p2)
533   = eq_hsPred env p1 p2
534
535 eq_hsType env (HsOpTy lty1 op1 rty1) (HsOpTy lty2 op2 rty2)
536   = eq_hsOp env op1 op2 && eq_hsType env lty1 lty2 && eq_hsType env rty1 rty2
537
538 eq_hsType env ty1 ty2 = False
539
540
541 eq_hsOp env (HsTyOp n1) (HsTyOp n2) = eq_hsVar env n1 n2
542 eq_hsOp env HsArrow     HsArrow     = True
543 eq_hsOp env op1         op2         = False
544
545 -------------------
546 eq_hsContext env a b = eqListBy (eq_hsPred env) a b
547
548 -------------------
549 eq_hsPred env (HsClassP c1 tys1) (HsClassP c2 tys2)
550   = c1 == c2 &&  eq_hsTypes env tys1 tys2
551 eq_hsPred env (HsIParam n1 ty1) (HsIParam n2 ty2)
552   = n1 == n2 && eq_hsType env ty1 ty2
553 eq_hsPred env _ _ = False
554 \end{code}