Type.hs 128 KB
Newer Older
1 2 3 4
-- (c) The University of Glasgow 2006
-- (c) The GRASP/AQUA Project, Glasgow University, 1998
--
-- Type - public interface
5

Gert-Jan Bottu's avatar
Gert-Jan Bottu committed
6
{-# LANGUAGE CPP, FlexibleContexts, PatternSynonyms #-}
7
{-# OPTIONS_GHC -fno-warn-orphans #-}
8
{-# OPTIONS_GHC -Wno-incomplete-record-updates #-}
Ian Lynagh's avatar
Ian Lynagh committed
9

batterseapower's avatar
batterseapower committed
10
-- | Main functions for manipulating types and type-related things
Sylvain Henry's avatar
Sylvain Henry committed
11
module GHC.Core.Type (
ian@well-typed.com's avatar
ian@well-typed.com committed
12
        -- Note some of this is just re-exports from TyCon..
13

batterseapower's avatar
batterseapower committed
14
        -- * Main data types representing Types
ian@well-typed.com's avatar
ian@well-typed.com committed
15 16
        -- $type_classification

batterseapower's avatar
batterseapower committed
17
        -- $representation_types
Ryan Scott's avatar
Ryan Scott committed
18
        TyThing(..), Type, ArgFlag(..), AnonArgFlag(..), ForallVisFlag(..),
Gert-Jan Bottu's avatar
Gert-Jan Bottu committed
19
        Specificity(..),
Simon Peyton Jones's avatar
Simon Peyton Jones committed
20
        KindOrType, PredType, ThetaType,
Ningning Xie's avatar
Ningning Xie committed
21
        Var, TyVar, isTyVar, TyCoVar, TyCoBinder, TyCoVarBinder, TyVarBinder,
22
        KnotTied,
23

batterseapower's avatar
batterseapower committed
24
        -- ** Constructing and deconstructing types
25
        mkTyVarTy, mkTyVarTys, getTyVar, getTyVar_maybe, repGetTyVar_maybe,
Ningning Xie's avatar
Ningning Xie committed
26
        getCastedTyVar_maybe, tyVarKind, varType,
27

eir@cis.upenn.edu's avatar
eir@cis.upenn.edu committed
28
        mkAppTy, mkAppTys, splitAppTy, splitAppTys, repSplitAppTys,
29
        splitAppTy_maybe, repSplitAppTy_maybe, tcRepSplitAppTy_maybe,
30

Simon Peyton Jones's avatar
Simon Peyton Jones committed
31 32
        mkVisFunTy, mkInvisFunTy, mkVisFunTys, mkInvisFunTys,
        splitFunTy, splitFunTy_maybe,
33
        splitFunTys, funResultTy, funArgTy,
34

ian@well-typed.com's avatar
ian@well-typed.com committed
35
        mkTyConApp, mkTyConTy,
36 37
        tyConAppTyCon_maybe, tyConAppTyConPicky_maybe,
        tyConAppArgs_maybe, tyConAppTyCon, tyConAppArgs,
Krzysztof Gogolewski's avatar
Krzysztof Gogolewski committed
38
        splitTyConApp_maybe, splitTyConApp, tyConAppArgN,
Simon Peyton Jones's avatar
Simon Peyton Jones committed
39
        tcSplitTyConApp_maybe,
40 41 42
        splitListTyConApp_maybe,
        repSplitTyConApp_maybe,

Gert-Jan Bottu's avatar
Gert-Jan Bottu committed
43
        mkForAllTy, mkForAllTys, mkInvisForAllTys, mkTyCoInvForAllTys,
44
        mkSpecForAllTy, mkSpecForAllTys,
Ningning Xie's avatar
Ningning Xie committed
45
        mkVisForAllTys, mkTyCoInvForAllTy,
Gert-Jan Bottu's avatar
Gert-Jan Bottu committed
46
        mkInfForAllTy, mkInfForAllTys,
47 48
        splitForAllTys, splitForAllTysSameVis,
        splitForAllVarBndrs,
Simon Peyton Jones's avatar
Simon Peyton Jones committed
49
        splitForAllTy_maybe, splitForAllTy,
Ningning Xie's avatar
Ningning Xie committed
50
        splitForAllTy_ty_maybe, splitForAllTy_co_maybe,
Simon Peyton Jones's avatar
Simon Peyton Jones committed
51
        splitPiTy_maybe, splitPiTy, splitPiTys,
Simon Peyton Jones's avatar
Simon Peyton Jones committed
52 53
        mkTyConBindersPreferAnon,
        mkPiTy, mkPiTys,
Simon Peyton Jones's avatar
Simon Peyton Jones committed
54
        mkLamType, mkLamTypes,
55
        piResultTy, piResultTys,
56
        applyTysX, dropForAlls,
57
        mkFamilyTyConApp,
58
        buildSynTyCon,
59

60 61
        mkNumLitTy, isNumLitTy,
        mkStrLitTy, isStrLitTy,
62
        isLitTy,
63

64 65
        isPredTy,

66
        getRuntimeRep_maybe, kindRep_maybe, kindRep,
Ben Gamari's avatar
Ben Gamari committed
67

Simon Peyton Jones's avatar
Simon Peyton Jones committed
68
        mkCastTy, mkCoercionTy, splitCastTy_maybe,
69
        discardCast,
70

71
        userTypeError_maybe, pprUserTypeErrorTy,
72

73
        coAxNthLHS,
74
        stripCoercionTy,
75

76 77 78
        splitPiTysInvisible, splitPiTysInvisibleN,
        invisibleTyBndrCount,
        filterOutInvisibleTypes, filterOutInferredTypes,
79 80
        partitionInvisibleTypes, partitionInvisibles,
        tyConArgFlags, appTyArgFlags,
81 82
        synTyConResKind,

lukemaurer's avatar
lukemaurer committed
83 84
        modifyJoinResTy, setJoinResTy,

85
        -- ** Analyzing types
86
        TyCoMapper(..), mapTyCo, mapTyCoX,
87
        TyCoFolder(..), foldTyCo,
ian@well-typed.com's avatar
ian@well-typed.com committed
88 89 90 91

        -- (Newtypes)
        newTyConInstRhs,

92
        -- ** Binders
93
        sameVis,
Ningning Xie's avatar
Ningning Xie committed
94 95
        mkTyCoVarBinder, mkTyCoVarBinders,
        mkTyVarBinders,
Gert-Jan Bottu's avatar
Gert-Jan Bottu committed
96
        tyVarSpecToBinders,
97
        mkAnonBinder,
98
        isAnonTyCoBinder,
Ningning Xie's avatar
Ningning Xie committed
99 100 101
        binderVar, binderVars, binderType, binderArgFlag,
        tyCoBinderType, tyCoBinderVar_maybe,
        tyBinderType,
Simon Peyton Jones's avatar
Simon Peyton Jones committed
102
        binderRelevantType_maybe,
103 104
        isVisibleArgFlag, isInvisibleArgFlag, isVisibleBinder,
        isInvisibleBinder, isNamedBinder,
Ningning Xie's avatar
Ningning Xie committed
105
        tyConBindersTyCoBinders,
106

ian@well-typed.com's avatar
ian@well-typed.com committed
107
        -- ** Common type constructors
batterseapower's avatar
batterseapower committed
108
        funTyCon,
109

batterseapower's avatar
batterseapower committed
110
        -- ** Predicates on types
111
        isTyVarTy, isFunTy, isCoercionTy,
112
        isCoercionTy_maybe, isForAllTy,
Ningning Xie's avatar
Ningning Xie committed
113
        isForAllTy_ty, isForAllTy_co,
114
        isPiTy, isTauTy, isFamFreeTy,
Simon Peyton Jones's avatar
Simon Peyton Jones committed
115
        isCoVarType, isAtomicTy,
batterseapower's avatar
batterseapower committed
116

lukemaurer's avatar
lukemaurer committed
117
        isValidJoinPointType,
Ben Gamari's avatar
Ben Gamari committed
118
        tyConAppNeedsKindSig,
lukemaurer's avatar
lukemaurer committed
119

120 121 122 123 124
        -- *** Levity and boxity
        isLiftedType_maybe,
        isLiftedTypeKind, isUnliftedTypeKind,
        isLiftedRuntimeRep, isUnliftedRuntimeRep,
        isUnliftedType, mightBeUnliftedType, isUnboxedTupleType, isUnboxedSumType,
125
        isAlgType, isDataFamilyAppType,
ian@well-typed.com's avatar
ian@well-typed.com committed
126
        isPrimitiveType, isStrictType,
127 128
        isRuntimeRepTy, isRuntimeRepVar, isRuntimeRepKindedTy,
        dropRuntimeRepArgs,
129
        getRuntimeRep,
130

ian@well-typed.com's avatar
ian@well-typed.com committed
131
        -- * Main data types representing Kinds
132
        Kind,
batterseapower's avatar
batterseapower committed
133 134

        -- ** Finding the kind of a type
135
        typeKind, tcTypeKind, isTypeLevPoly, resultIsLevPoly,
136
        tcIsLiftedTypeKind, tcIsConstraintKind, tcReturnsConstraintKind,
137
        tcIsRuntimeTypeKind,
ian@well-typed.com's avatar
ian@well-typed.com committed
138

139
        -- ** Common Kind
140
        liftedTypeKind,
batterseapower's avatar
batterseapower committed
141

ian@well-typed.com's avatar
ian@well-typed.com committed
142
        -- * Type free variables
143
        tyCoFVsOfType, tyCoFVsBndr, tyCoFVsVarBndr, tyCoFVsVarBndrs,
Simon Peyton Jones's avatar
Simon Peyton Jones committed
144
        tyCoVarsOfType, tyCoVarsOfTypes,
145 146
        tyCoVarsOfTypeDSet,
        coVarsOfType,
Tobias Dammers's avatar
Tobias Dammers committed
147 148
        coVarsOfTypes,

Richard Eisenberg's avatar
Richard Eisenberg committed
149
        noFreeVarsOfType,
150
        splitVisVarsOfType, splitVisVarsOfTypes,
ian@well-typed.com's avatar
ian@well-typed.com committed
151
        expandTypeSynonyms,
152
        typeSize, occCheckExpand,
153

154
        -- ** Closing over kinds
Simon Peyton Jones's avatar
Simon Peyton Jones committed
155
        closeOverKindsDSet, closeOverKindsList,
156 157
        closeOverKinds,

158
        -- * Well-scoped lists of variables
159 160
        scopedSort, tyCoVarsOfTypeWellScoped,
        tyCoVarsOfTypesWellScoped,
161

ian@well-typed.com's avatar
ian@well-typed.com committed
162
        -- * Type comparison
niteria's avatar
niteria committed
163 164
        eqType, eqTypeX, eqTypes, nonDetCmpType, nonDetCmpTypes, nonDetCmpTypeX,
        nonDetCmpTypesX, nonDetCmpTc,
165
        eqVarBndrs,
166

ian@well-typed.com's avatar
ian@well-typed.com committed
167
        -- * Forcing evaluation of types
batterseapower's avatar
batterseapower committed
168
        seqType, seqTypes,
169

batterseapower's avatar
batterseapower committed
170
        -- * Other views onto Types
Ben Gamari's avatar
Ben Gamari committed
171
        coreView, tcView,
batterseapower's avatar
batterseapower committed
172

173
        tyConsOfType,
batterseapower's avatar
batterseapower committed
174

ian@well-typed.com's avatar
ian@well-typed.com committed
175 176
        -- * Main type substitution data types
        TvSubstEnv,     -- Representation widely visible
177
        TCvSubst(..),    -- Representation visible to a few friends
ian@well-typed.com's avatar
ian@well-typed.com committed
178 179

        -- ** Manipulating type substitutions
180
        emptyTvSubstEnv, emptyTCvSubst, mkEmptyTCvSubst,
ian@well-typed.com's avatar
ian@well-typed.com committed
181

niteria's avatar
niteria committed
182
        mkTCvSubst, zipTvSubst, mkTvSubstPrs,
Ningning Xie's avatar
Ningning Xie committed
183
        zipTCvSubst,
184
        notElemTCvSubst,
185
        getTvSubstEnv, setTvSubstEnv,
186
        zapTCvSubst, getTCvInScope, getTCvSubstRangeFVs,
187
        extendTCvInScope, extendTCvInScopeList, extendTCvInScopeSet,
188
        extendTCvSubst, extendCvSubst,
Richard Eisenberg's avatar
Richard Eisenberg committed
189
        extendTvSubst, extendTvSubstBinderAndInScope,
190
        extendTvSubstList, extendTvSubstAndInScope,
Ningning Xie's avatar
Ningning Xie committed
191
        extendTCvSubstList,
192
        extendTvSubstWithClone,
Ningning Xie's avatar
Ningning Xie committed
193
        extendTCvSubstWithClone,
194 195
        isInScope, composeTCvSubstEnv, composeTCvSubst, zipTyEnv, zipCoEnv,
        isEmptyTCvSubst, unionTCvSubst,
196

ian@well-typed.com's avatar
ian@well-typed.com committed
197 198
        -- ** Performing substitution on types and kinds
        substTy, substTys, substTyWith, substTysWith, substTheta,
199 200
        substTyAddInScope,
        substTyUnchecked, substTysUnchecked, substThetaUnchecked,
201
        substTyWithUnchecked,
202
        substCoUnchecked, substCoWithUnchecked,
Simon Peyton Jones's avatar
Simon Peyton Jones committed
203
        substTyVarBndr, substTyVarBndrs, substTyVar, substTyVars,
Ningning Xie's avatar
Ningning Xie committed
204
        substVarBndr, substVarBndrs,
205
        cloneTyVarBndr, cloneTyVarBndrs, lookupTyVar,
206

Simon Peyton Jones's avatar
Simon Peyton Jones committed
207 208 209 210
        -- * Tidying type related things up for printing
        tidyType,      tidyTypes,
        tidyOpenType,  tidyOpenTypes,
        tidyOpenKind,
Ningning Xie's avatar
Ningning Xie committed
211
        tidyVarBndr, tidyVarBndrs, tidyFreeTyCoVars,
212
        tidyOpenTyCoVar, tidyOpenTyCoVars,
Ningning Xie's avatar
Ningning Xie committed
213
        tidyTyCoVarOcc,
Simon Peyton Jones's avatar
Simon Peyton Jones committed
214
        tidyTopType,
215
        tidyKind,
216 217 218 219 220 221
        tidyTyCoVarBinder, tidyTyCoVarBinders,

        -- * Kinds
        isConstraintKindCon,
        classifiesTypeWithValues,
        isKindLevPoly
222
    ) where
223

224 225
#include "HsVersions.h"

226
import GHC.Prelude
227

Sylvain Henry's avatar
Sylvain Henry committed
228
import GHC.Types.Basic
lukemaurer's avatar
lukemaurer committed
229

Sylvain Henry's avatar
Sylvain Henry committed
230
-- We import the representation and primitive functions from GHC.Core.TyCo.Rep.
231 232
-- Many things are reexported, but not the representation!

Sylvain Henry's avatar
Sylvain Henry committed
233 234 235 236
import GHC.Core.TyCo.Rep
import GHC.Core.TyCo.Subst
import GHC.Core.TyCo.Tidy
import GHC.Core.TyCo.FVs
237

238
-- friends:
Sylvain Henry's avatar
Sylvain Henry committed
239 240 241 242
import GHC.Types.Var
import GHC.Types.Var.Env
import GHC.Types.Var.Set
import GHC.Types.Unique.Set
243

Sylvain Henry's avatar
Sylvain Henry committed
244
import GHC.Core.TyCon
Sylvain Henry's avatar
Sylvain Henry committed
245 246 247
import GHC.Builtin.Types.Prim
import {-# SOURCE #-} GHC.Builtin.Types
                                 ( listTyCon, typeNatKind
248
                                 , typeSymbolKind, liftedTypeKind
249
                                 , liftedTypeKindTyCon
250
                                 , constraintKind )
Sylvain Henry's avatar
Sylvain Henry committed
251
import GHC.Types.Name( Name )
Sylvain Henry's avatar
Sylvain Henry committed
252
import GHC.Builtin.Names
Sylvain Henry's avatar
Sylvain Henry committed
253 254 255 256 257 258 259 260 261 262
import GHC.Core.Coercion.Axiom
import {-# SOURCE #-} GHC.Core.Coercion
   ( mkNomReflCo, mkGReflCo, mkReflCo
   , mkTyConAppCo, mkAppCo, mkCoVarCo, mkAxiomRuleCo
   , mkForAllCo, mkFunCo, mkAxiomInstCo, mkUnivCo
   , mkSymCo, mkTransCo, mkNthCo, mkLRCo, mkInstCo
   , mkKindCo, mkSubCo, mkFunCo, mkAxiomInstCo
   , decomposePiCos, coercionKind, coercionLKind
   , coercionRKind, coercionType
   , isReflexiveCo, seqCo )
263

264
-- others
265 266 267 268 269 270
import GHC.Utils.Misc
import GHC.Utils.FV
import GHC.Utils.Outputable
import GHC.Data.FastString
import GHC.Data.Pair
import GHC.Data.List.SetOps
Sylvain Henry's avatar
Sylvain Henry committed
271
import GHC.Types.Unique ( nonDetCmpUnique )
simonpj@microsoft.com's avatar
simonpj@microsoft.com committed
272

273
import GHC.Data.Maybe   ( orElse )
Tobias Dammers's avatar
Tobias Dammers committed
274
import Data.Maybe       ( isJust )
275
import Control.Monad    ( guard )
276

batterseapower's avatar
batterseapower committed
277 278
-- $type_classification
-- #type_classification#
ian@well-typed.com's avatar
ian@well-typed.com committed
279
--
batterseapower's avatar
batterseapower committed
280
-- Types are one of:
ian@well-typed.com's avatar
ian@well-typed.com committed
281
--
batterseapower's avatar
batterseapower committed
282
-- [Unboxed]            Iff its representation is other than a pointer
ian@well-typed.com's avatar
ian@well-typed.com committed
283 284
--                      Unboxed types are also unlifted.
--
batterseapower's avatar
batterseapower committed
285
-- [Lifted]             Iff it has bottom as an element.
ian@well-typed.com's avatar
ian@well-typed.com committed
286 287 288 289 290 291
--                      Closures always have lifted types: i.e. any
--                      let-bound identifier in Core must have a lifted
--                      type. Operationally, a lifted object is one that
--                      can be entered.
--                      Only lifted types may be unified with a type variable.
--
batterseapower's avatar
batterseapower committed
292
-- [Algebraic]          Iff it is a type with one or more constructors, whether
ian@well-typed.com's avatar
ian@well-typed.com committed
293 294 295 296 297 298
--                      declared with @data@ or @newtype@.
--                      An algebraic type is one that can be deconstructed
--                      with a case expression. This is /not/ the same as
--                      lifted types, because we also include unboxed
--                      tuples in this classification.
--
batterseapower's avatar
batterseapower committed
299
-- [Data]               Iff it is a type declared with @data@, or a boxed tuple.
ian@well-typed.com's avatar
ian@well-typed.com committed
300
--
batterseapower's avatar
batterseapower committed
301
-- [Primitive]          Iff it is a built-in type that can't be expressed in Haskell.
ian@well-typed.com's avatar
ian@well-typed.com committed
302
--
batterseapower's avatar
batterseapower committed
303 304
-- Currently, all primitive types are unlifted, but that's not necessarily
-- the case: for example, @Int@ could be primitive.
ian@well-typed.com's avatar
ian@well-typed.com committed
305
--
batterseapower's avatar
batterseapower committed
306 307 308
-- Some primitive types are unboxed, such as @Int#@, whereas some are boxed
-- but unlifted (such as @ByteArray#@).  The only primitive types that we
-- classify as algebraic are the unboxed tuples.
ian@well-typed.com's avatar
ian@well-typed.com committed
309
--
batterseapower's avatar
batterseapower committed
310
-- Some examples of type classifications that may make this a bit clearer are:
ian@well-typed.com's avatar
ian@well-typed.com committed
311
--
batterseapower's avatar
batterseapower committed
312
-- @
313
-- Type          primitive       boxed           lifted          algebraic
batterseapower's avatar
batterseapower committed
314
-- -----------------------------------------------------------------------------
315 316 317 318 319 320
-- Int#          Yes             No              No              No
-- ByteArray#    Yes             Yes             No              No
-- (\# a, b \#)  Yes             No              No              Yes
-- (\# a | b \#) Yes             No              No              Yes
-- (  a, b  )    No              Yes             Yes             Yes
-- [a]           No              Yes             Yes             Yes
batterseapower's avatar
batterseapower committed
321 322 323 324 325
-- @

-- $representation_types
-- A /source type/ is a type that is a separate type as far as the type checker is
-- concerned, but which has a more low-level representation as far as Core-to-Core
batterseapower's avatar
batterseapower committed
326
-- passes and the rest of the back end is concerned.
batterseapower's avatar
batterseapower committed
327 328 329
--
-- You don't normally have to worry about this, as the utility functions in
-- this module will automatically convert a source into a representation type
Ningning Xie's avatar
Ningning Xie committed
330
-- if they are spotted, to the best of its abilities. If you don't want this
batterseapower's avatar
batterseapower committed
331
-- to happen, use the equivalent functions from the "TcType" module.
332

333 334 335
{-
************************************************************************
*                                                                      *
ian@well-typed.com's avatar
ian@well-typed.com committed
336
                Type representation
337 338
*                                                                      *
************************************************************************
Ben Gamari's avatar
Ben Gamari committed
339 340 341

Note [coreView vs tcView]
~~~~~~~~~~~~~~~~~~~~~~~~~
342 343
So far as the typechecker is concerned, 'Constraint' and 'TYPE
LiftedRep' are distinct kinds.
Ben Gamari's avatar
Ben Gamari committed
344 345 346

But in Core these two are treated as identical.

347 348 349
We implement this by making 'coreView' convert 'Constraint' to 'TYPE
LiftedRep' on the fly.  The function tcView (used in the type checker)
does not do this.
Ben Gamari's avatar
Ben Gamari committed
350

351
See also #11715, which tracks removing this inconsistency.
Ben Gamari's avatar
Ben Gamari committed
352

353
-}
354

Ben Gamari's avatar
Ben Gamari committed
355 356 357
-- | Gives the typechecker view of a type. This unwraps synonyms but
-- leaves 'Constraint' alone. c.f. coreView, which turns Constraint into
-- TYPE LiftedRep. Returns Nothing if no unwrapping happens.
358
-- See also Note [coreView vs tcView]
Ben Gamari's avatar
Ben Gamari committed
359 360 361 362 363 364
{-# INLINE tcView #-}
tcView :: Type -> Maybe Type
tcView (TyConApp tc tys) | Just (tenv, rhs, tys') <- expandSynTyCon_maybe tc tys
  = Just (mkAppTys (substTy (mkTvSubstPrs tenv) rhs) tys')
               -- The free vars of 'rhs' should all be bound by 'tenv', so it's
               -- ok to use 'substTy' here.
Sylvain Henry's avatar
Sylvain Henry committed
365
               -- See also Note [The substitution invariant] in GHC.Core.TyCo.Subst.
Ben Gamari's avatar
Ben Gamari committed
366 367 368 369
               -- Its important to use mkAppTys, rather than (foldl AppTy),
               -- because the function part might well return a
               -- partially-applied type constructor; indeed, usually will!
tcView _ = Nothing
370

371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
{-# INLINE coreView #-}
coreView :: Type -> Maybe Type
-- ^ This function Strips off the /top layer only/ of a type synonym
-- application (if any) its underlying representation type.
-- Returns Nothing if there is nothing to look through.
-- This function considers 'Constraint' to be a synonym of @TYPE LiftedRep@.
--
-- By being non-recursive and inlined, this case analysis gets efficiently
-- joined onto the case analysis that the caller is already doing
coreView ty@(TyConApp tc tys)
  | Just (tenv, rhs, tys') <- expandSynTyCon_maybe tc tys
  = Just (mkAppTys (substTy (mkTvSubstPrs tenv) rhs) tys')
    -- This equation is exactly like tcView

  -- At the Core level, Constraint = Type
  -- See Note [coreView vs tcView]
  | isConstraintKindCon tc
  = ASSERT2( null tys, ppr ty )
    Just liftedTypeKind

coreView _ = Nothing

393 394 395 396 397
-----------------------------------------------
expandTypeSynonyms :: Type -> Type
-- ^ Expand out all type synonyms.  Actually, it'd suffice to expand out
-- just the ones that discard type variables (e.g.  type Funny a = Int)
-- But we don't know which those are currently, so we just expand all.
398 399 400
--
-- 'expandTypeSynonyms' only expands out type synonyms mentioned in the type,
-- not in the kinds of any TyCon or TyVar mentioned in the type.
401 402
--
-- Keep this synchronized with 'synonymTyConsOfType'
ian@well-typed.com's avatar
ian@well-typed.com committed
403
expandTypeSynonyms ty
404
  = go (mkEmptyTCvSubst in_scope) ty
405
  where
406 407
    in_scope = mkInScopeSet (tyCoVarsOfType ty)

408
    go subst (TyConApp tc tys)
409 410 411 412 413 414 415 416
      | Just (tenv, rhs, tys') <- expandSynTyCon_maybe tc expanded_tys
      = let subst' = mkTvSubst in_scope (mkVarEnv tenv)
            -- Make a fresh substitution; rhs has nothing to
            -- do with anything that has happened so far
            -- NB: if you make changes here, be sure to build an
            --     /idempotent/ substitution, even in the nested case
            --        type T a b = a -> b
            --        type S x y = T y x
417
            -- (#11665)
418
        in  mkAppTys (go subst' rhs) tys'
419
      | otherwise
420 421 422 423
      = TyConApp tc expanded_tys
      where
        expanded_tys = (map (go subst) tys)

424 425 426
    go _     (LitTy l)     = LitTy l
    go subst (TyVarTy tv)  = substTyVar subst tv
    go subst (AppTy t1 t2) = mkAppTy (go subst t1) (go subst t2)
Simon Peyton Jones's avatar
Simon Peyton Jones committed
427 428
    go subst ty@(FunTy _ arg res)
      = ty { ft_arg = go subst arg, ft_res = go subst res }
Ningning Xie's avatar
Ningning Xie committed
429 430 431
    go subst (ForAllTy (Bndr tv vis) t)
      = let (subst', tv') = substVarBndrUsing go subst tv in
        ForAllTy (Bndr tv' vis) (go subst' t)
432 433 434
    go subst (CastTy ty co)  = mkCastTy (go subst ty) (go_co subst co)
    go subst (CoercionTy co) = mkCoercionTy (go_co subst co)

Ningning Xie's avatar
Ningning Xie committed
435 436 437 438 439 440 441
    go_mco _     MRefl    = MRefl
    go_mco subst (MCo co) = MCo (go_co subst co)

    go_co subst (Refl ty)
      = mkNomReflCo (go subst ty)
    go_co subst (GRefl r ty mco)
      = mkGReflCo r (go subst ty) (go_mco subst mco)
442 443 444 445 446 447 448 449
       -- NB: coercions are always expanded upon creation
    go_co subst (TyConAppCo r tc args)
      = mkTyConAppCo r tc (map (go_co subst) args)
    go_co subst (AppCo co arg)
      = mkAppCo (go_co subst co) (go_co subst arg)
    go_co subst (ForAllCo tv kind_co co)
      = let (subst', tv', kind_co') = go_cobndr subst tv kind_co in
        mkForAllCo tv' kind_co' (go_co subst' co)
Ben Gamari's avatar
Ben Gamari committed
450 451
    go_co subst (FunCo r co1 co2)
      = mkFunCo r (go_co subst co1) (go_co subst co2)
452 453 454 455 456 457 458 459 460 461
    go_co subst (CoVarCo cv)
      = substCoVar subst cv
    go_co subst (AxiomInstCo ax ind args)
      = mkAxiomInstCo ax ind (map (go_co subst) args)
    go_co subst (UnivCo p r t1 t2)
      = mkUnivCo (go_prov subst p) r (go subst t1) (go subst t2)
    go_co subst (SymCo co)
      = mkSymCo (go_co subst co)
    go_co subst (TransCo co1 co2)
      = mkTransCo (go_co subst co1) (go_co subst co2)
462 463
    go_co subst (NthCo r n co)
      = mkNthCo r n (go_co subst co)
464 465 466 467 468 469 470 471
    go_co subst (LRCo lr co)
      = mkLRCo lr (go_co subst co)
    go_co subst (InstCo co arg)
      = mkInstCo (go_co subst co) (go_co subst arg)
    go_co subst (KindCo co)
      = mkKindCo (go_co subst co)
    go_co subst (SubCo co)
      = mkSubCo (go_co subst co)
Simon Peyton Jones's avatar
Simon Peyton Jones committed
472 473 474 475
    go_co subst (AxiomRuleCo ax cs)
      = AxiomRuleCo ax (map (go_co subst) cs)
    go_co _ (HoleCo h)
      = pprPanic "expandTypeSynonyms hit a hole" (ppr h)
476 477 478 479 480 481

    go_prov subst (PhantomProv co)    = PhantomProv (go_co subst co)
    go_prov subst (ProofIrrelProv co) = ProofIrrelProv (go_co subst co)
    go_prov _     p@(PluginProv _)    = p

      -- the "False" and "const" are to accommodate the type of
Simon Peyton Jones's avatar
Simon Peyton Jones committed
482
      -- substForAllCoBndrUsing, which is general enough to
483 484
      -- handle coercion optimization (which sometimes swaps the
      -- order of a coercion)
Simon Peyton Jones's avatar
Simon Peyton Jones committed
485
    go_cobndr subst = substForAllCoBndrUsing False (go_co subst) subst
486

487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561

-- | Extract the RuntimeRep classifier of a type from its kind. For example,
-- @kindRep * = LiftedRep@; Panics if this is not possible.
-- Treats * and Constraint as the same
kindRep :: HasDebugCallStack => Kind -> Type
kindRep k = case kindRep_maybe k of
              Just r  -> r
              Nothing -> pprPanic "kindRep" (ppr k)

-- | Given a kind (TYPE rr), extract its RuntimeRep classifier rr.
-- For example, @kindRep_maybe * = Just LiftedRep@
-- Returns 'Nothing' if the kind is not of form (TYPE rr)
-- Treats * and Constraint as the same
kindRep_maybe :: HasDebugCallStack => Kind -> Maybe Type
kindRep_maybe kind
  | Just kind' <- coreView kind = kindRep_maybe kind'
  | TyConApp tc [arg] <- kind
  , tc `hasKey` tYPETyConKey    = Just arg
  | otherwise                   = Nothing

-- | This version considers Constraint to be the same as *. Returns True
-- if the argument is equivalent to Type/Constraint and False otherwise.
-- See Note [Kind Constraint and kind Type]
isLiftedTypeKind :: Kind -> Bool
isLiftedTypeKind kind
  = case kindRep_maybe kind of
      Just rep -> isLiftedRuntimeRep rep
      Nothing  -> False

isLiftedRuntimeRep :: Type -> Bool
-- isLiftedRuntimeRep is true of LiftedRep :: RuntimeRep
-- False of type variables (a :: RuntimeRep)
--   and of other reps e.g. (IntRep :: RuntimeRep)
isLiftedRuntimeRep rep
  | Just rep' <- coreView rep          = isLiftedRuntimeRep rep'
  | TyConApp rr_tc args <- rep
  , rr_tc `hasKey` liftedRepDataConKey = ASSERT( null args ) True
  | otherwise                          = False

-- | Returns True if the kind classifies unlifted types and False otherwise.
-- Note that this returns False for levity-polymorphic kinds, which may
-- be specialized to a kind that classifies unlifted types.
isUnliftedTypeKind :: Kind -> Bool
isUnliftedTypeKind kind
  = case kindRep_maybe kind of
      Just rep -> isUnliftedRuntimeRep rep
      Nothing  -> False

isUnliftedRuntimeRep :: Type -> Bool
-- True of definitely-unlifted RuntimeReps
-- False of           (LiftedRep :: RuntimeRep)
--   and of variables (a :: RuntimeRep)
isUnliftedRuntimeRep rep
  | Just rep' <- coreView rep = isUnliftedRuntimeRep rep'
  | TyConApp rr_tc _ <- rep   -- NB: args might be non-empty
                              --     e.g. TupleRep [r1, .., rn]
  = isPromotedDataCon rr_tc && not (rr_tc `hasKey` liftedRepDataConKey)
        -- Avoid searching all the unlifted RuntimeRep type cons
        -- In the RuntimeRep data type, only LiftedRep is lifted
        -- But be careful of type families (F tys) :: RuntimeRep
  | otherwise {- Variables, applications -}
  = False

-- | Is this the type 'RuntimeRep'?
isRuntimeRepTy :: Type -> Bool
isRuntimeRepTy ty | Just ty' <- coreView ty = isRuntimeRepTy ty'
isRuntimeRepTy (TyConApp tc args)
  | tc `hasKey` runtimeRepTyConKey = ASSERT( null args ) True
isRuntimeRepTy _ = False

-- | Is a tyvar of type 'RuntimeRep'?
isRuntimeRepVar :: TyVar -> Bool
isRuntimeRepVar = isRuntimeRepTy . tyVarKind


562
{- *********************************************************************
563
*                                                                      *
564
               mapType
565 566 567 568 569 570
*                                                                      *
************************************************************************

These functions do a map-like operation over types, performing some operation
on all variables and binding sites. Primarily used for zonking.

571
Note [Efficiency for ForAllCo case of mapTyCoX]
572
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sylvain Henry's avatar
Sylvain Henry committed
573
As noted in Note [Forall coercions] in GHC.Core.TyCo.Rep, a ForAllCo is a bit redundant.
Ningning Xie's avatar
Ningning Xie committed
574
It stores a TyCoVar and a Coercion, where the kind of the TyCoVar always matches
575 576 577
the left-hand kind of the coercion. This is convenient lots of the time, but
not when mapping a function over a coercion.

Ningning Xie's avatar
Ningning Xie committed
578
The problem is that tcm_tybinder will affect the TyCoVar's kind and
579 580 581 582 583 584 585 586 587 588 589 590 591 592
mapCoercion will affect the Coercion, and we hope that the results will be
the same. Even if they are the same (which should generally happen with
correct algorithms), then there is an efficiency issue. In particular,
this problem seems to make what should be a linear algorithm into a potentially
exponential one. But it's only going to be bad in the case where there's
lots of foralls in the kinds of other foralls. Like this:

  forall a : (forall b : (forall c : ...). ...). ...

This construction seems unlikely. So we'll do the inefficient, easy way
for now.

Note [Specialising mappers]
~~~~~~~~~~~~~~~~~~~~~~~~~~~
593
These INLINE pragmas are indispensable. mapTyCo and mapTyCoX are used
594
to implement zonking, and it's vital that they get specialised to the TcM
595
monad and the particular mapper in use.
596

597 598 599
Even specialising to the monad alone made a 20% allocation difference
in perf/compiler/T5030.

600
See Note [Specialising foldType] in "GHC.Core.TyCo.Rep" for more details of this
601
idiom.
602 603 604 605 606
-}

-- | This describes how a "map" operation over a type/coercion should behave
data TyCoMapper env m
  = TyCoMapper
607
      { tcm_tyvar :: env -> TyVar -> m Type
608
      , tcm_covar :: env -> CoVar -> m Coercion
Simon Peyton Jones's avatar
Simon Peyton Jones committed
609 610
      , tcm_hole  :: env -> CoercionHole -> m Coercion
          -- ^ What to do with coercion holes.
Sylvain Henry's avatar
Sylvain Henry committed
611
          -- See Note [Coercion holes] in GHC.Core.TyCo.Rep.
612

Ningning Xie's avatar
Ningning Xie committed
613
      , tcm_tycobinder :: env -> TyCoVar -> ArgFlag -> m (env, TyCoVar)
614
          -- ^ The returned env is used in the extended scope
615 616

      , tcm_tycon :: TyCon -> m TyCon
Simon Peyton Jones's avatar
Simon Peyton Jones committed
617 618 619 620
          -- ^ This is used only for TcTyCons
          -- a) To zonk TcTyCons
          -- b) To turn TcTyCons into TyCons.
          --    See Note [Type checking recursive type and class declarations]
Sylvain Henry's avatar
Sylvain Henry committed
621
          --    in GHC.Tc.TyCl
622 623
      }

624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
{-# INLINE mapTyCo #-}  -- See Note [Specialising mappers]
mapTyCo :: Monad m => TyCoMapper () m
         -> ( Type       -> m Type
            , [Type]     -> m [Type]
            , Coercion   -> m Coercion
            , [Coercion] -> m[Coercion])
mapTyCo mapper
  = case mapTyCoX mapper of
     (go_ty, go_tys, go_co, go_cos)
        -> (go_ty (), go_tys (), go_co (), go_cos ())

{-# INLINE mapTyCoX #-}  -- See Note [Specialising mappers]
mapTyCoX :: Monad m => TyCoMapper env m
         -> ( env -> Type       -> m Type
            , env -> [Type]     -> m [Type]
            , env -> Coercion   -> m Coercion
            , env -> [Coercion] -> m[Coercion])
mapTyCoX (TyCoMapper { tcm_tyvar = tyvar
                     , tcm_tycobinder = tycobinder
                     , tcm_tycon = tycon
                     , tcm_covar = covar
                     , tcm_hole = cohole })
  = (go_ty, go_tys, go_co, go_cos)
647
  where
648 649 650 651 652 653 654 655 656 657 658
    go_tys _   []       = return []
    go_tys env (ty:tys) = (:) <$> go_ty env ty <*> go_tys env tys

    go_ty env (TyVarTy tv)    = tyvar env tv
    go_ty env (AppTy t1 t2)   = mkAppTy <$> go_ty env t1 <*> go_ty env t2
    go_ty _   ty@(LitTy {})   = return ty
    go_ty env (CastTy ty co)  = mkCastTy <$> go_ty env ty <*> go_co env co
    go_ty env (CoercionTy co) = CoercionTy <$> go_co env co

    go_ty env ty@(FunTy _ arg res)
      = do { arg' <- go_ty env arg; res' <- go_ty env res
Simon Peyton Jones's avatar
Simon Peyton Jones committed
659 660
           ; return (ty { ft_arg = arg', ft_res = res' }) }

661
    go_ty env ty@(TyConApp tc tys)
Simon Peyton Jones's avatar
Simon Peyton Jones committed
662
      | isTcTyCon tc
663
      = do { tc' <- tycon tc
664
           ; mkTyConApp tc' <$> go_tys env tys }
Simon Peyton Jones's avatar
Simon Peyton Jones committed
665 666 667 668 669 670

      -- Not a TcTyCon
      | null tys    -- Avoid allocation in this very
      = return ty   -- common case (E.g. Int, LiftedRep etc)

      | otherwise
671
      = mkTyConApp tc <$> go_tys env tys
Simon Peyton Jones's avatar
Simon Peyton Jones committed
672

673
    go_ty env (ForAllTy (Bndr tv vis) inner)
Ningning Xie's avatar
Ningning Xie committed
674
      = do { (env', tv') <- tycobinder env tv vis
675
           ; inner' <- go_ty env' inner
Ningning Xie's avatar
Ningning Xie committed
676
           ; return $ ForAllTy (Bndr tv' vis) inner' }
677

678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
    go_cos _   []       = return []
    go_cos env (co:cos) = (:) <$> go_co env co <*> go_cos env cos

    go_mco _   MRefl    = return MRefl
    go_mco env (MCo co) = MCo <$> (go_co env co)

    go_co env (Refl ty)           = Refl <$> go_ty env ty
    go_co env (GRefl r ty mco)    = mkGReflCo r <$> go_ty env ty <*> go_mco env mco
    go_co env (AppCo c1 c2)       = mkAppCo <$> go_co env c1 <*> go_co env c2
    go_co env (FunCo r c1 c2)     = mkFunCo r <$> go_co env c1 <*> go_co env c2
    go_co env (CoVarCo cv)        = covar env cv
    go_co env (HoleCo hole)       = cohole env hole
    go_co env (UnivCo p r t1 t2)  = mkUnivCo <$> go_prov env p <*> pure r
                                    <*> go_ty env t1 <*> go_ty env t2
    go_co env (SymCo co)          = mkSymCo <$> go_co env co
    go_co env (TransCo c1 c2)     = mkTransCo <$> go_co env c1 <*> go_co env c2
    go_co env (AxiomRuleCo r cos) = AxiomRuleCo r <$> go_cos env cos
    go_co env (NthCo r i co)      = mkNthCo r i <$> go_co env co
    go_co env (LRCo lr co)        = mkLRCo lr <$> go_co env co
    go_co env (InstCo co arg)     = mkInstCo <$> go_co env co <*> go_co env arg
    go_co env (KindCo co)         = mkKindCo <$> go_co env co
    go_co env (SubCo co)          = mkSubCo <$> go_co env co
    go_co env (AxiomInstCo ax i cos) = mkAxiomInstCo ax i <$> go_cos env cos
    go_co env co@(TyConAppCo r tc cos)
      | isTcTyCon tc
      = do { tc' <- tycon tc
           ; mkTyConAppCo r tc' <$> go_cos env cos }

      -- Not a TcTyCon
      | null cos    -- Avoid allocation in this very
      = return co   -- common case (E.g. Int, LiftedRep etc)

      | otherwise
      = mkTyConAppCo r tc <$> go_cos env cos
    go_co env (ForAllCo tv kind_co co)
      = do { kind_co' <- go_co env kind_co
Ningning Xie's avatar
Ningning Xie committed
714
           ; (env', tv') <- tycobinder env tv Inferred
715
           ; co' <- go_co env' co
716
           ; return $ mkForAllCo tv' kind_co' co' }
717 718 719 720 721
        -- See Note [Efficiency for ForAllCo case of mapTyCoX]

    go_prov env (PhantomProv co)    = PhantomProv <$> go_co env co
    go_prov env (ProofIrrelProv co) = ProofIrrelProv <$> go_co env co
    go_prov _   p@(PluginProv _)    = return p
722

723

724 725 726
{-
************************************************************************
*                                                                      *
727
\subsection{Constructor-specific functions}
728 729
*                                                                      *
************************************************************************
sof's avatar
sof committed
730 731


732
---------------------------------------------------------------------
ian@well-typed.com's avatar
ian@well-typed.com committed
733 734
                                TyVarTy
                                ~~~~~~~
735 736
-}

batterseapower's avatar
batterseapower committed
737 738
-- | Attempts to obtain the type variable underlying a 'Type', and panics with the
-- given message if this is not a type variable type. See also 'getTyVar_maybe'
739
getTyVar :: String -> Type -> TyVar
740
getTyVar msg ty = case getTyVar_maybe ty of
ian@well-typed.com's avatar
ian@well-typed.com committed
741 742
                    Just tv -> tv
                    Nothing -> panic ("getTyVar: " ++ msg)
743

744
isTyVarTy :: Type -> Bool
745 746
isTyVarTy ty = isJust (getTyVar_maybe ty)

batterseapower's avatar
batterseapower committed
747
-- | Attempts to obtain the type variable underlying a 'Type'
748
getTyVar_maybe :: Type -> Maybe TyVar
749
getTyVar_maybe ty | Just ty' <- coreView ty = getTyVar_maybe ty'
750 751 752
                  | otherwise               = repGetTyVar_maybe ty

-- | If the type is a tyvar, possibly under a cast, returns it, along
Ningning Xie's avatar
Ningning Xie committed
753
-- with the coercion. Thus, the co is :: kind tv ~N kind ty
754
getCastedTyVar_maybe :: Type -> Maybe (TyVar, CoercionN)
755 756 757 758 759 760 761 762 763 764 765
getCastedTyVar_maybe ty | Just ty' <- coreView ty = getCastedTyVar_maybe ty'
getCastedTyVar_maybe (CastTy (TyVarTy tv) co)     = Just (tv, co)
getCastedTyVar_maybe (TyVarTy tv)
  = Just (tv, mkReflCo Nominal (tyVarKind tv))
getCastedTyVar_maybe _                            = Nothing

-- | Attempts to obtain the type variable underlying a 'Type', without
-- any expansion
repGetTyVar_maybe :: Type -> Maybe TyVar
repGetTyVar_maybe (TyVarTy tv) = Just tv
repGetTyVar_maybe _            = Nothing
766

767
{-
768
---------------------------------------------------------------------
ian@well-typed.com's avatar
ian@well-typed.com committed
769 770 771
                                AppTy
                                ~~~~~
We need to be pretty careful with AppTy to make sure we obey the
772 773
invariant that a TyConApp is always visibly so.  mkAppTy maintains the
invariant: use it.
774 775 776 777 778

Note [Decomposing fat arrow c=>t]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Can we unify (a b) with (Eq a => ty)?   If we do so, we end up with
a partial application like ((=>) Eq a) which doesn't make sense in
Gabor Greif's avatar
Gabor Greif committed
779
source Haskell.  In contrast, we *can* unify (a b) with (t1 -> t2).
780
Here's an example (#9858) of how you might do it:
781 782 783 784 785 786 787 788 789 790 791
   i :: (Typeable a, Typeable b) => Proxy (a b) -> TypeRep
   i p = typeRep p

   j = i (Proxy :: Proxy (Eq Int => Int))
The type (Proxy (Eq Int => Int)) is only accepted with -XImpredicativeTypes,
but suppose we want that.  But then in the call to 'i', we end
up decomposing (Eq Int => Int), and we definitely don't want that.

This really only applies to the type checker; in Core, '=>' and '->'
are the same, as are 'Constraint' and '*'.  But for now I've put
the test in repSplitAppTy_maybe, which applies throughout, because
Sylvain Henry's avatar
Sylvain Henry committed
792
the other calls to splitAppTy are in GHC.Core.Unify, which is also used by
793
the type checker (e.g. when matching type-function equations).
794

795
-}
796

batterseapower's avatar
batterseapower committed
797
-- | Applies a type to another, as in e.g. @k a@
798
mkAppTy :: Type -> Type -> Type
799 800
  -- See Note [Respecting definitional equality], invariant (EQ1).
mkAppTy (CastTy fun_ty co) arg_ty
801
  | ([arg_co], res_co) <- decomposePiCos co (coercionKind co) [arg_ty]
802 803
  = (fun_ty `mkAppTy` (arg_ty `mkCastTy` arg_co)) `mkCastTy` res_co

804 805
mkAppTy (TyConApp tc tys) ty2 = mkTyConApp tc (tys ++ [ty2])
mkAppTy ty1               ty2 = AppTy ty1 ty2
ian@well-typed.com's avatar
ian@well-typed.com committed
806 807 808 809 810 811 812 813
        -- Note that the TyConApp could be an
        -- under-saturated type synonym.  GHC allows that; e.g.
        --      type Foo k = k a -> k a
        --      type Id x = x
        --      foo :: Foo Id -> Foo Id
        --
        -- Here Id is partially applied in the type sig for Foo,
        -- but once the type synonyms are expanded all is well
Simon Peyton Jones's avatar
Simon Peyton Jones committed
814
        --
Simon Peyton Jones's avatar
Simon Peyton Jones committed
815
        -- Moreover in GHC.Tc.Types.tcInferTyApps we build up a type
Simon Peyton Jones's avatar
Simon Peyton Jones committed
816 817
        --   (T t1 t2 t3) one argument at a type, thus forming
        --   (T t1), (T t1 t2), etc
818

819
mkAppTys :: Type -> [Type] -> Type
ian@well-typed.com's avatar
ian@well-typed.com committed
820
mkAppTys ty1                []   = ty1
821 822 823
mkAppTys (CastTy fun_ty co) arg_tys  -- much more efficient then nested mkAppTy
                                     -- Why do this? See (EQ1) of
                                     -- Note [Respecting definitional equality]
Sylvain Henry's avatar
Sylvain Henry committed
824
                                     -- in GHC.Core.TyCo.Rep
825
  = foldl' AppTy ((mkAppTys fun_ty casted_arg_tys) `mkCastTy` res_co) leftovers
826
  where
827
    (arg_cos, res_co) = decomposePiCos co (coercionKind co) arg_tys
828 829
    (args_to_cast, leftovers) = splitAtList arg_cos arg_tys
    casted_arg_tys = zipWith mkCastTy args_to_cast arg_cos
830
mkAppTys (TyConApp tc tys1) tys2 = mkTyConApp tc (tys1 ++ tys2)
831
mkAppTys ty1                tys2 = foldl' AppTy ty1 tys2
832

833
-------------
834
splitAppTy_maybe :: Type -> Maybe (Type, Type)
batterseapower's avatar
batterseapower committed
835 836 837
-- ^ Attempt to take a type application apart, whether it is a
-- function, type constructor, or plain type application. Note
-- that type family applications are NEVER unsaturated by this!
838
splitAppTy_maybe ty | Just ty' <- coreView ty
ian@well-typed.com's avatar
ian@well-typed.com committed
839
                    = splitAppTy_maybe ty'
840
splitAppTy_maybe ty = repSplitAppTy_maybe ty
841