[英]GHC 7.8 binding substitution fails to type check
鑒於支持代碼:
{-# LANGUAGE ExtendedDefaultRules, DeriveDataTypeable #-}
{-# LANGUAGE FlexibleInstances, UndecidableInstances, OverlappingInstances #-}
import Data.Typeable
default(A)
data A = A deriving (Eq,Show,Typeable)
class Show a => Testable2 a where
instance (Show a, Eq a) => Testable2 a where
instance (Show a, Testable2 b) => Testable2 (a -> b) where
instance (Show a, Show b) => Show (a -> b) where show _ = "<func>"
test :: (Show p, Typeable p, Testable2 p) => p -> IO ()
test = print . typeOf
在GHC 7.6中,我可以寫:
main = test (\f -> (f $))
那種類型檢查和打印:
(A -> A) -> A -> A
但是,在GHC 7.8中,我得到:
Main.hs:
No instance for (Eq (a0 -> b0)) arising from a use of `test'
但是,如果我重構:
main = let ff = \f -> (f $) in test ff
然后它在GHC 7.8和GHC 7.6中都能正常工作。 為什么?
支持代碼背后的邏輯是Show (a -> b)
的實例,其中Show
上下文強制類型默認,然后是一種處理默認原子(使用Eq
)的方法,以及一種將某些東西移回->
for Testable2
。 該代碼旨在允許可變的QuickCheck屬性,並取自hlint 。
似乎test (\\ x -> x)
甚至不用GHC 7.6.3編譯。 另一方面:
($$) = ($)
main = test (\ f -> (f $$))
與兩者編譯。 我懷疑默認不會發生非廣義/單態類型變量與($)
特殊內置處理相結合。
復制用戶kosmikus'評論的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.