Type Family Polymorphism

So, I have a function apply :: proxy tf -> tf Int -> tf Int , which uses a proxy server to transfer the type family, and applies Int to this type to determine the type of the second argument and return value. However, I get some confusing answers from the GHC.

 {-# LANGUAGE TypeFamilies #-} import Data.Proxy type family F (a :: *) :: * where F Int = () f :: Proxy F f = Proxy apply :: proxy tf -> tf Int -> tf Int apply _ x = x -- Doesn't typecheck. test1 :: () test1 = apply f () -- Typechecks fine test2 :: () test2 = let g = apply f in g () 

test1 refuses to compile with GHC, spitting out this error:

 tftest.hs:16:9: Couldn't match expected type '()' with actual type 'F Int' In the expression: apply f () In an equation for 'test1': test1 = apply f () tftest.hs:16:17: Couldn't match expected type 'F Int' with actual type '()' In the second argument of 'apply', namely '()' In the expression: apply f () 

Vaguely commenting on test1 and using the let binding in test2 makes GHC happy and everything compiles fine. Can anyone explain what is going on here?

+8
polymorphism haskell type-families
source share
1 answer

So, I have a function apply :: proxy tf -> tf Int -> tf Int , which accepts a proxy server designed to migrate a type family

You cannot do this. Family types should always be fully applied, like type synonyms, which are generalizations. A type variable can never be created for an undersaturated family.

It is a mistake in GHC 7.8.3 that it has not yet rejected your program, starting with

 f :: Proxy F 
+12
source share

All Articles