How to instantiate typeclass for advanced type?

I have a data type that I promote with DataKinds in ghc 7.4.1 and a given type that I want to use for type type operations.

data Type = TInt32 | TInt64 | TInt16 class TypeTraits a where ... 

And then I try to instantiate typeclass for promoted types, for example:

 instance TypeTraits TInt32 where ... 

I get errors of the following type:

 Kind mis-match The first argument of `TypeTraits' should have kind `*', but `TInt32' has kind `Type' In the instance declaration for `TypeTraits TInt32' 

tries to fix this by specifying type 'a':

 class TypeTraits (a :: Type) where ... Kind mis-match Expected kind `ArgKind', but `a' has kind `Type' In the type `a -> String' In the class declaration for `TypeTraits' 
+6
source share
1 answer

The problem is in the body of the class; types that have a raised look have no meaning, so you cannot have a function that takes one parameter. You will need to use Proxy a -> String or similar.

By the way, if you enable the PolyKinds extension, you must completely omit the view annotation. (In fact, you may have to do this to determine your own Proxy type, since I think that one of Data.Proxy can be * -> * , whereas you need Type -> * . If you define data Proxy p = Proxy using PolyKinds on, it will be displayed as AnyK -> * .)

+7
source

Source: https://habr.com/ru/post/913970/


All Articles