[project @ 1996-07-25 20:43:49 by partain]
[ghc-hetmet.git] / ghc / compiler / types / Kind.lhs
index 0b247e4..ab77d19 100644 (file)
@@ -4,6 +4,8 @@
 \section[Kind]{The @Kind@ datatype}
 
 \begin{code}
+#include "HsVersions.h"
+
 module Kind (
        Kind(..),               -- Only visible to friends: TcKind
 
@@ -12,13 +14,18 @@ module Kind (
        mkUnboxedTypeKind,
        mkBoxedTypeKind,
 
-       isSubKindOf,
-       resultKind, argKind
+       hasMoreBoxityInfo,
+       resultKind, argKind,
+
+       isUnboxedKind, isTypeKind,
+       notArrowKind
     ) where
 
-import Ubiq{-uitous-}
+IMP_Ubiq(){-uitous-}
 
-import Util            ( panic )
+import Util            ( panic, assertPanic )
+--import Outputable    ( Outputable(..) )
+import Pretty
 \end{code}
 
 \begin{code}
@@ -34,11 +41,34 @@ mkTypeKind            = TypeKind
 mkUnboxedTypeKind = UnboxedTypeKind
 mkBoxedTypeKind   = BoxedTypeKind
 
-isSubKindOf :: Kind -> Kind -> Bool
+isTypeKind :: Kind -> Bool
+isTypeKind TypeKind = True
+isTypeKind other    = False
+
+isUnboxedKind :: Kind -> Bool
+isUnboxedKind UnboxedTypeKind  = True
+isUnboxedKind other            = False
+
+hasMoreBoxityInfo :: Kind -> Kind -> Bool
+
+BoxedTypeKind  `hasMoreBoxityInfo` TypeKind        = True
+BoxedTypeKind   `hasMoreBoxityInfo` BoxedTypeKind   = True
+
+UnboxedTypeKind `hasMoreBoxityInfo` TypeKind       = True
+UnboxedTypeKind `hasMoreBoxityInfo` UnboxedTypeKind = True
+
+TypeKind       `hasMoreBoxityInfo` TypeKind        = True
 
-BoxedTypeKind   `isSubKindOf` TypeKind = True
-UnboxedTypeKind `isSubKindOf` TypeKind = True
-kind1          `isSubKindOf` kind2    = kind1 == kind2
+kind1@(ArrowKind _ _) `hasMoreBoxityInfo` kind2@(ArrowKind _ _) = ASSERT( kind1 == kind2 )
+                                                                 True
+       -- The two kinds can be arrow kinds; for example when unifying
+       -- (m1 Int) and (m2 Int) we end up unifying m1 and m2, which should
+       -- have the same kind.
+
+kind1          `hasMoreBoxityInfo` kind2           = False
+
+notArrowKind (ArrowKind _ _) = False
+notArrowKind other_kind             = True
 
 resultKind :: Kind -> Kind     -- Get result from arrow kind
 resultKind (ArrowKind _ res_kind) = res_kind
@@ -48,3 +78,18 @@ argKind :: Kind -> Kind              -- Get argument from arrow kind
 argKind (ArrowKind arg_kind _) = arg_kind
 argKind other_kind            = panic "argKind"
 \end{code}
+
+Printing
+~~~~~~~~
+\begin{code}
+instance Outputable Kind where
+  ppr sty kind = pprKind kind
+
+pprKind TypeKind        = ppStr "*"
+pprKind BoxedTypeKind   = ppStr "*b"
+pprKind UnboxedTypeKind = ppStr "*u"
+pprKind (ArrowKind k1 k2) = ppSep [pprKind_parend k1, ppStr "->", pprKind k2]
+
+pprKind_parend k@(ArrowKind _ _) = ppBesides [ppLparen, pprKind k, ppRparen]
+pprKind_parend k                = pprKind k
+\end{code}