forked from purescript/purescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKinds.hs
More file actions
58 lines (49 loc) · 1.53 KB
/
Copy pathKinds.hs
File metadata and controls
58 lines (49 loc) · 1.53 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
-- |
-- Pretty printer for kinds
--
module Language.PureScript.Pretty.Kinds
( prettyPrintKind
) where
import Prelude.Compat
import Control.Arrow (ArrowPlus(..))
import Control.PatternArrows as PA
import Data.Monoid ((<>))
import Data.Maybe (fromMaybe)
import qualified Data.Text as T
import Data.Text (Text)
import Language.PureScript.Crash
import Language.PureScript.Kinds
import Language.PureScript.Names
import Language.PureScript.Pretty.Common
typeLiterals :: Pattern () Kind Text
typeLiterals = mkPattern match
where
match (KUnknown u) =
Just $ T.cons 'k' (T.pack (show u))
match (NamedKind name) =
Just $ if isQualifiedWith (moduleNameFromString "Prim") name
then runProperName (disqualify name)
else showQualified runProperName name
match _ = Nothing
matchRow :: Pattern () Kind ((), Kind)
matchRow = mkPattern match
where
match (Row k) = Just ((), k)
match _ = Nothing
funKind :: Pattern () Kind (Kind, Kind)
funKind = mkPattern match
where
match (FunKind arg ret) = Just (arg, ret)
match _ = Nothing
-- | Generate a pretty-printed string representing a Kind
prettyPrintKind :: Kind -> Text
prettyPrintKind
= fromMaybe (internalError "Incomplete pattern")
. PA.pattern matchKind ()
where
matchKind :: Pattern () Kind Text
matchKind = buildPrettyPrinter operators (typeLiterals <+> fmap parensT matchKind)
operators :: OperatorTable () Kind Text
operators =
OperatorTable [ [ Wrap matchRow $ \_ k -> "# " <> k]
, [ AssocR funKind $ \arg ret -> arg <> " -> " <> ret ] ]