Bu yüzden, bir tür ailesini taşımayı amaçlayan bir Proxy alan ve ikinci bağımsız değişken ve dönüş değeri türünü belirlemek için bu tür aileye Int uygulayan bir işlevi olan apply :: proxy tf -> tf Int -> tf Int
işlevim var. Ancak, GHC'den bazı kafa karıştırıcı yanıtlar alıyorum. Tip Aile Polimorfizmi
{-# 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
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()
Ait, test1
dışında yorum ve test2
yılında bağlama let kullanarak GHC mutlu ediyor ve her şey iyi derler. Burada neler olduğunu açıklayan var mı?