首先,您需要提供
NFData
单例列表的实例。
instance NFData (SList '[]) where
rnf SNil = ()
instance (NFData (Sing x), NFData (SList xs)) => NFData (SList (x ': xs)) where
rnf (SCons x xs) = rnf x `seq` rnf xs
请注意,您不能在单个实例中解决此问题,因为这样就不能提供递归
NFData公司
约束条件:
instance NFData (SList xs) where
rnf SNil = ()
rnf (SCons x xs) = ? -- no way to know if NFData (Sing x)
类似地,您必须为
T
案例:
instance NFData (ST A) where
rnf SA = ()
instance NFData (SList xs) => NFData (ST (B xs)) where
rnf (SB xs) = rnf xs