File: Rank.hs

package info (click to toggle)
haskell-ghc-lib-parser 9.6.6.20240701-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,280 kB
  • sloc: haskell: 109,582; yacc: 3,744; ansic: 2,480; makefile: 12
file content (40 lines) | stat: -rw-r--r-- 1,471 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module GHC.Tc.Types.Rank (Rank(..))  where

import GHC.Base (Bool)
import GHC.Utils.Outputable (Outputable, (<+>), parens, ppr, text)

{-
Note [Higher rank types]
~~~~~~~~~~~~~~~~~~~~~~~~
Technically
            Int -> forall a. a->a
is still a rank-1 type, but it's not Haskell 98 (#5957).  So the
validity checker allow a forall after an arrow only if we allow it
before -- that is, with Rank2Types or RankNTypes
-}

data Rank = ArbitraryRank -- Any rank ok

          | LimitedRank   -- Note [Higher rank types]
                 Bool     -- Forall ok at top
                 Rank     -- Use for function arguments

          -- Monotypes that could be a polytype through an extension
          | MonoTypeRankZero   -- RankNTypes
          | MonoTypeTyConArg   -- ImpredicativeTypes
          | MonoTypeSynArg     -- LiberalTypeSynonyms
          | MonoTypeConstraint -- QuantifiedConstraints
          --

          | MustBeMonoType  -- Monotype regardless of flags

instance Outputable Rank where
  ppr ArbitraryRank      = text "ArbitraryRank"
  ppr (LimitedRank top_forall_ok r)
                         = text "LimitedRank" <+> ppr top_forall_ok
                                              <+> parens (ppr r)
  ppr MonoTypeRankZero   = text "MonoTypeRankZero"
  ppr MonoTypeTyConArg   = text "MonoTypeTyConArg"
  ppr MonoTypeSynArg     = text "MonoTypeSynArg"
  ppr MonoTypeConstraint = text "MonoTypeConstraint"
  ppr MustBeMonoType     = text "MustBeMonoType"