@@ -19,54 +19,4 @@ import Data.Word ( Word8, Word16, Word32, Word64 )
1919import Type.Reflection (TypeRep , typeOf , typeRep )
2020import Data.Type.Equality (TestEquality (.. ))
2121
22- -- We need an "Object" type as an intermediate representation
23- -- for rows. Useful for things like sorting and function application.
2422type Columnable' a = (Typeable a , Show a , Ord a , Eq a )
25-
26- data RowValue where
27- Value :: (Columnable' a ) => a -> RowValue
28-
29- instance Eq RowValue where
30- (==) :: RowValue -> RowValue -> Bool
31- (Value a) == (Value b) = fromMaybe False $ do
32- Refl <- testEquality (typeOf a) (typeOf b)
33- return $ a == b
34-
35- instance Ord RowValue where
36- (<=) :: RowValue -> RowValue -> Bool
37- (Value a) <= (Value b) = fromMaybe False $ do
38- Refl <- testEquality (typeOf a) (typeOf b)
39- return $ a <= b
40-
41- instance Show RowValue where
42- show :: RowValue -> String
43- show (Value a) = show a
44-
45- toRowValue :: forall a . (Columnable' a ) => a -> RowValue
46- toRowValue = Value
47-
48- -- Convenience functions for types.
49- unboxableTypes :: TypeRepList '[Int , Int8 , Int16 , Int32 , Int64 ,
50- Word , Word8 , Word16 , Word32 , Word64 ,
51- Char , Double , Float , Bool ]
52- unboxableTypes = Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep Nil )))))))))))))
53-
54- numericTypes :: TypeRepList '[Int , Int8 , Int16 , Int32 , Int64 , Double , Float ]
55- numericTypes = Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep (Cons typeRep Nil ))))))
56-
57- data TypeRepList (xs :: [Type ]) where
58- Nil :: TypeRepList '[]
59- Cons :: Typeable x => TypeRep x -> TypeRepList xs -> TypeRepList (x ': xs )
60-
61- matchesAnyType :: forall a xs . (Typeable a ) => TypeRepList xs -> TypeRep a -> Bool
62- matchesAnyType Nil _ = False
63- matchesAnyType (Cons ty tys) rep =
64- case testEquality ty rep of
65- Just Refl -> True
66- Nothing -> matchesAnyType tys rep
67-
68- testUnboxable :: forall a . Typeable a => TypeRep a -> Bool
69- testUnboxable x = matchesAnyType unboxableTypes (typeRep @ a )
70-
71- testNumeric :: forall a . Typeable a => TypeRep a -> Bool
72- testNumeric x = matchesAnyType numericTypes (typeRep @ a )
0 commit comments