haskell - Type Family Polymorphism -


so have function apply :: proxy tf -> tf int -> tf int takes proxy intended carry type family , applies int type family determine type of second argument , return value. however, i'm getting confusing responses ghc.

{-# language typefamilies #-}  import data.proxy  type family f (a :: *) :: *     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 compile ghc spitting out error:

tftest.hs:16:9:     couldn't match expected type ‘()’ actual type ‘f int’     in expression: apply f ()     in equation ‘test1’: test1 = apply f ()  tftest.hs:16:17:     couldn't match expected type ‘f int’ actual type ‘()’     in second argument of ‘apply’, namely ‘()’     in expression: apply f () 

confusingly, commenting out test1 , using let binding in test2 makes ghc happy , compiles fine. can explain what's going on here?

so have function apply :: proxy tf -> tf int -> tf int takes proxy intended carry type family

you can't this. type families must applied, type synonyms of generalization. type variable can never instantiated under-saturated type family.

it's bug in ghc 7.8.3 did not reject program starting at

f :: proxy f 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -