我正在尝试为具有lens字段的数据类型生成lens。
data St st l = St {
_st_s :: String,
_st_lens :: Lens' st l
}
st_lens :: forall st l. Lens' (St st l) (Lens' st l)
st_lens = lens _st_lens (\s a -> s { _st_lens = a })
GHC 8.10.7 给我报错:
Illegal polymorphic type:
forall (f1 :: * -> *). Functor f1 => (l -> f1 l) -> st -> f1 st
GHC doesn't yet support impredicative polymorphism
• In the expansion of type synonym ‘Lens’
BlockArguments
和ScopedTypeVariables
,在GHC 8.10中这对我不起作用。错误是Couldn't match expected type ‘(l -> f1 l) -> st -> f1 st’ with actual type ‘Lens' st l’
。它在9.2中运行良好,但如果您只启用ImpredicativeTypes
而不需要任何类型应用程序,则提问者的原始代码也可以正常工作。 - Joseph Sible-Reinstate Monica