shithub: MicroHs

Download patch

ref: 92c26abbcd947c9f2edb2597db4f64f4c66bcc40
parent: ddd6ef6148a2ea3902b7b80ed89d80cea89acfcf
author: Lennart Augustsson <lennart@augustsson.net>
date: Mon Dec 25 10:33:19 EST 2023

Use polykinds in Typeable.

--- a/lib/Data/Typeable.hs
+++ b/lib/Data/Typeable.hs
@@ -16,10 +16,6 @@
   funResultTy,
   typeRepTyCon,
   typeRepArgs,
-{-
-  typeOf1, typeOf2, typeOf3, typeOf4, typeOf5, typeOf6, typeOf7,
-  Typeable1, Typeable2, Typeable3, Typeable4, Typeable5, Typeable6, Typeable7,
--}
   ) where
 import Primitives
 import Prelude
@@ -37,7 +33,7 @@
 import System.IO.MD5
 import Unsafe.Coerce
 
---type  Typeable :: forall k . k -> Constraint
+type  Typeable :: forall k . k -> Constraint
 class Typeable a where
   typeRep :: forall proxy . proxy a -> TypeRep
 
@@ -85,7 +81,7 @@
   TyCon k1 _ _ <= TyCon k2 _ _  =  k1 <= k2
 
 instance Show TyCon where
-  showsPrec _ (TyCon _ m n) = showString m . showChar '.' . showString n
+  showsPrec _ (TyCon _ m n) = showString n
 
 tyConModule :: TyCon -> String
 tyConModule (TyCon _ m _) = m
@@ -98,10 +94,10 @@
   where md5 = md5String $ show $ m ++ "." ++ n
 
 mkFunTy  :: TypeRep -> TypeRep -> TypeRep
-mkFunTy f a = mkTyConApp funTc [f,a]
+mkFunTy f a = mkTyConApp funTc [f, a]
 
 splitTyConApp :: TypeRep -> (TyCon,[TypeRep])
-splitTyConApp (TypeRep _ tc trs) = (tc,trs)
+splitTyConApp (TypeRep _ tc trs) = (tc, trs)
 
 funTc :: TyCon
 funTc = mkTyCon "Primitives" "->"
@@ -109,7 +105,7 @@
 funResultTy :: TypeRep -> TypeRep -> Maybe TypeRep
 funResultTy trFun trArg
   = case splitTyConApp trFun of
-      (tc, [t1,t2]) | tc == funTc && t1 == trArg -> Just t2
+      (tc, [t1, t2]) | tc == funTc && t1 == trArg -> Just t2
       _ -> Nothing
 
 -----------------
@@ -138,46 +134,47 @@
 nullary :: forall a . String -> String -> a -> TypeRep
 nullary m n _ = mkTyConApp (mkTyCon m n) []
 
-unary :: forall proxy t a .
-         Typeable a => String -> String -> proxy (t a) -> TypeRep
-unary m n _ = mkTyConApp (mkTyCon m n) [typeRep (Proxy :: Proxy a)]
-
-binary :: forall proxy t a b .
-         (Typeable a, Typeable b) => String -> String -> proxy (t a b) -> TypeRep
-binary m n _ = mkTyConApp (mkTyCon m n) [typeRep (Proxy :: Proxy a), typeRep (Proxy :: Proxy b)]
-
 prim :: forall a . String -> a -> TypeRep
 prim n = nullary "Primitives" n
 
-instance Typeable ()      where typeRep = nullary "Data.Tuple" "()"
-instance Typeable Any     where typeRep = prim "Any"
-instance Typeable Bool    where typeRep = nullary "Data.Bool_Type" "Char"
-instance Typeable Char    where typeRep = prim "Char"
-instance Typeable Int     where typeRep = prim "Int"
-instance Typeable Integer where typeRep = nullary "Data.Integer_Type" "Integer"
-instance Typeable Double  where typeRep = prim "Double"
-instance Typeable Void    where typeRep = nullary "Data.Void" "Void"
-instance Typeable Word    where typeRep = prim "Word"
-instance Typeable Word8   where typeRep = nullary "Data.Word8" "Word8"
+instance Typeable ()          where typeRep = nullary "Data.Tuple"          "()"
+instance Typeable Any         where typeRep = prim                          "Any"
+instance Typeable Bool        where typeRep = nullary "Data.Bool_Type"      "Char"
+instance Typeable Char        where typeRep = prim                          "Char"
+instance Typeable Int         where typeRep = prim                          "Int"
+instance Typeable Integer     where typeRep = nullary "Data.Integer_Type"   "Integer"
+instance Typeable Double      where typeRep = prim                          "Double"
+instance Typeable Void        where typeRep = nullary "Data.Void"           "Void"
+instance Typeable Word        where typeRep = prim                          "Word"
+instance Typeable Word8       where typeRep = nullary "Data.Word8"          "Word8"
 
-instance Typeable TypeRep where typeRep = nullary "Data.Typeable" "TypeRep"
-instance Typeable TyCon   where typeRep = nullary "Data.Typeable" "TyCon"
+instance Typeable TypeRep     where typeRep = nullary "Data.Typeable"       "TypeRep"
+instance Typeable TyCon       where typeRep = nullary "Data.Typeable"       "TyCon"
 
-instance forall a . Typeable a => Typeable (IO a)      where typerep = unary "Primitives" "IO"
-instance forall a . Typeable a => Typeable (Ptr a)     where typeRep = unary "Primitives" "Ptr"
-instance forall a . Typeable a => Typeable (IOArray a) where typeRep = unary "Primitives" "IOArray"
-instance forall a . Typeable a => Typeable (IORef a)   where typeRep = unary "Data.IORef" "IORef"
-instance forall a . Typeable a => Typeable (IntMap a)  where typeRep = unary "Data.IntMap" "IntMap"
+instance Typeable IO          where typeRep = prim                          "IO"
+instance Typeable Ptr         where typeRep = prim                          "Ptr"
+instance Typeable IOArray     where typeRep = prim                          "IOArray"
+instance Typeable IORef       where typeRep = nullary "Data.IORef"          "IORef"
+instance Typeable IntMap      where typeRep = nullary "Data.IntMap"         "IntMap"
 
-instance forall a . Typeable a => Typeable [a]         where typeRep = unary "Data.List_Type" "[]"
-instance forall a . Typeable a => Typeable (Complex a) where typeRep = unary "Data.Complex" "Complex"
-instance forall a . Typeable a => Typeable (Maybe a)   where typeRep = unary "Data.Maybe_Type" "Maybe"
-instance forall a . Typeable a => Typeable (Proxy a)   where typeRep = unary "Data.Proxy" "Proxy"
-instance forall a . Typeable a => Typeable (Ratio a)   where typeRep = unary "Data.Ratio" "Ratio"
+instance Typeable []          where typeRep = nullary "Data.List_Type"      "[]"
+instance Typeable Complex     where typeRep = nullary "Data.Complex"        "Complex"
+instance Typeable Maybe       where typeRep = nullary "Data.Maybe_Type"     "Maybe"
+instance Typeable Proxy       where typeRep = nullary "Data.Proxy"          "Proxy"
+instance Typeable Ratio       where typeRep = nullary "Data.Ratio"          "Ratio"
+instance Typeable Functor     where typeRep = nullary "Data.Functor"        "Functor"
+instance Typeable Applicative where typeRep = nullary "Control.Applicative" "Applicative"
+instance Typeable Monad       where typeRep = nullary "Control.Monad"       "Monad"
 
-instance forall a b . (Typeable a, Typeable b) => Typeable (a, b)       where typeRep = binary "Data.Tuple" ","
-instance forall a b . (Typeable a, Typeable b) => Typeable (a -> b)     where typeRep = binary "Primitives" "->"
-instance forall a b . (Typeable a, Typeable b) => Typeable (Either a b) where typeRep = binary "Data.Either" "Either"
-instance forall a b . (Typeable a, Typeable b) => Typeable (Map a b)    where typeRep = binary "Data.Map" "Map"
-instance forall a b . (Typeable a, Typeable b) => Typeable (ST a b)     where typeRep = binary "Control.Monad.ST" "ST"
-instance forall a b . (Typeable a, Typeable b) => Typeable (STRef a b)  where typeRep = binary "Data.STRef" "STRef"
+instance Typeable (,)         where typeRep = nullary "Data.Tuple"          ","
+instance Typeable (->)        where typeRep = nullary "Primitives"          "->"
+instance Typeable Either      where typeRep = nullary "Data.Either"         "Either"
+instance Typeable Map         where typeRep = nullary "Data.Map"            "Map"
+instance Typeable ST          where typeRep = nullary "Control.Monad.ST"    "ST"
+instance Typeable STRef       where typeRep = nullary "Data.STRef"          "STRef"
+
+instance Typeable (,,)        where typeRep = nullary "Data.Tuple"          ",,"
+instance Typeable (,,,)       where typeRep = nullary "Data.Tuple"          ",,,"
+
+instance forall f a . (Typeable f, Typeable a) => Typeable (f a) where
+  typeRep _ = mkAppTy (typeRep (Proxy :: Proxy f)) (typeRep (Proxy :: Proxy a))
--- a/src/MicroHs/TCMonad.hs
+++ b/src/MicroHs/TCMonad.hs
@@ -269,7 +269,7 @@
   = TCExpr          -- doing type checking
   | TCType          -- doing kind checking
   | TCKind          -- doing sort checking
-  | TCSort
+  | TCSort          -- doing realm checking
   --deriving (Show)
 
 instance Show TCMode where
--