shithub: MicroHs

Download patch

ref: 3b9c34f8b0ddd235e9a969f1246aab87f7dbd471
parent: d7c1383311e70717d2d7f0d511d3d08de2115698
author: Lennart Augustsson <lennart@augustsson.net>
date: Sun Dec 24 08:14:07 EST 2023

Add test for polykinds

--- a/tests/Makefile
+++ b/tests/Makefile
@@ -53,6 +53,7 @@
 	$(TMHS) IOArray    && $(EVAL) > IOArray.out    && diff IOArray.ref IOArray.out
 	$(TMHS) ST         && $(EVAL) > ST.out         && diff ST.ref ST.out
 	$(TMHS) HigherKind && $(EVAL) > HigherKind.out && diff HigherKind.ref HigherKind.out
+	$(TMHS) PolyKind   && $(EVAL) > PolyKind.out   && diff PolyKind.ref PolyKind.out
 
 errtest:
 	sh errtester.sh < errmsg.test
--- /dev/null
+++ b/tests/PolyKind.hs
@@ -1,0 +1,36 @@
+module PolyKind(main) where
+import Prelude
+
+type Proxy :: forall (k::Kind) . k -> Type
+data Proxy a = Proxy
+
+data TypeRep = TypeRep String [TypeRep]
+
+mkAppTy :: TypeRep -> TypeRep -> TypeRep
+mkAppTy (TypeRep tc trs) tr = TypeRep tc (trs ++ [tr])
+
+instance Show TypeRep where
+  show (TypeRep s []) = s
+  show (TypeRep s ts) = "(" ++ unwords (s : map show ts) ++ ")"
+
+type  Typeable :: forall (k::Kind) . k -> Constraint
+class Typeable a where
+  typeRep :: forall proxy . proxy a -> TypeRep
+
+typeOf :: forall a . Typeable a => a -> TypeRep
+typeOf _ = typeRep (Proxy :: Proxy a)
+
+instance Typeable Int where
+  typeRep _ = TypeRep "Int" []
+
+instance Typeable IO where
+  typeRep _ = TypeRep "IO" []
+
+instance forall f a . (Typeable f, Typeable a) => Typeable (f a) where
+  typeRep _ = mkAppTy (typeRep (Proxy :: Proxy f)) (typeRep (Proxy :: Proxy a))
+
+main :: IO ()
+main = do
+  print $ typeRep (Proxy :: Proxy Int)
+  print $ typeRep (Proxy :: Proxy IO)
+  print $ typeRep (Proxy :: Proxy (IO Int))
--- /dev/null
+++ b/tests/PolyKind.ref
@@ -1,0 +1,3 @@
+Int
+IO
+(IO Int)
--