11package CPrintType where
22
3+ import List
4+
35class CPrintType a where
46 cPrintType :: a -> String
57 cPrintTypeP :: a -> String
@@ -63,14 +65,44 @@ instance CPrintTypeArg (NumArg n) where
6365instance CPrintTypeArg (StrArg s ) where
6466 cPrintTypeArg _ = " \" " +++ stringOf s +++ " \" "
6567
68+ instance (CPrintConType (c () )) => CPrintTypeArg (StarConArg c ) where
69+ cPrintTypeArg _ = cPrintConType (_ :: c () )
70+
71+ instance (CPrintConType (c 0 )) => CPrintTypeArg (NumConArg c ) where
72+ cPrintTypeArg _ = cPrintConType (_ :: c 0 )
73+
6674instance CPrintTypeArg OtherConArg where
6775 cPrintTypeArg _ = " ?"
6876
77+ class CPrintConType c where
78+ cPrintConType :: c -> String
79+
80+ instance (Generic c r , CPrintConType' r ) => CPrintConType c where
81+ cPrintConType _ = cPrintConType' (_ :: r )
82+
83+ class CPrintConType' r where
84+ cPrintConType' :: r -> String
85+
86+ instance CPrintConType' (Meta (MetaData n p ta nc ) r ) where
87+ cPrintConType' _ = stringOf p +++ " ." +++ stringOf n
88+
89+ instance (InitTuple (a , b ) ta , CPrintTypeArgs ta ) =>
90+ CPrintConType' (Meta (MetaData n p (a , b ) nc ) r ) where
91+ cPrintConType' _ = " (" +++ stringOf p +++ " ." +++ stringOf n +++
92+ " " +++ cPrintTypeArgs (_ :: ta ) +++ " )"
93+
94+ class InitTuple a b | a -> b where {}
95+ instance (InitTuple (b , c ) d ) => InitTuple (a , b , c ) (a , d ) where {}
96+ instance InitTuple (a , b ) a where {}
6997
7098data Foo a b = A (UInt a )
7199 | B b Bool (Bit a )
72100 | C
73101
102+ data (Bar :: (* -> *) -> *) a = Bar (a Bool )
103+ data (Baz :: (# -> *) -> (* -> * -> *) -> *) a b = Baz (a 42 ) (b Bool Integer )
104+ data MyBit n = MyBit (Bit n )
105+
74106sysCPrintType :: Module Empty
75107sysCPrintType = module
76108 rules
@@ -81,4 +113,7 @@ sysCPrintType = module
81113 $ display (cPrintType (_ :: Foo 16 Real ))
82114 $ display (cPrintType $ from (_ :: Foo 16 Real ))
83115 $ display (cPrintType (_ :: Maybe (String , Integer )))
116+ $ display (cPrintType (_ :: Bar Maybe ))
117+ $ display (cPrintType (_ :: Bar (Either Integer )))
118+ $ display (cPrintType (_ :: Baz MyBit Either ))
84119 $ finish
0 commit comments