所以 Data.MapdataCast2定义了,这是有道理的,因为它有一个 arity 2 类型的构造函数。dataCast1默认为const Nothing. dataCast2很容易定义为gcast2。
以供参考:
class Typeable a => Data a where
dataCast1 :: Typeable1 t => (forall d. Data d => c (t d)) -> Maybe (c a)
dataCast2 :: Typeable2 t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a)
...
gcast1 :: (Typeable1 t, Typeable1 t') => c (t a) -> Maybe (c (t' a))
gcast2 :: (Typeable2 t, Typeable2 t') => c (t a b) -> Maybe (c (t' a b))
手头的问题是:给定 , 等中的所有内容Data.Data,Data.Typeable并给定一个已定义的 arity 2 类型构造dataCast2函数(例如Map, 或(,)),是否有可能编写一个dataCast1对部分专业化做正确事情的版本这种类型的构造函数,一次用于一个特定的构造函数,还是一般?
直觉上,我认为应该有一个很好的解决方案,但我最初的几次尝试都崩溃了。