我目前正在通过阅读Purescript by Example书来学习 Purescript (迄今为止我发现的唯一涵盖该语言的资源之一)。
我正在尝试实现第 6.7 节(实例依赖性)中的练习,但我无法理解以下编译器错误:
我已经为数据类型实现了 Semigroup 和 Eq 实例,data NonEmpty a = NonEmpty a (Array a)如下所示:
instance eqNonEmpty :: Eq a => Eq (NonEmpty a) where
eq (NonEmpty h1 t1) (NonEmpty h2 t2) = h1 == h2 && t1 == t2
instance semigroupNonEmpty :: Semigroup (NonEmpty a) where
append (NonEmpty h1 t1) (NonEmpty h2 t2) = NonEmpty h1 (t1 <> [h2] <> t2)
Run Code Online (Sandbox Code Playgroud)
但是当我尝试以同样的方式实现 Functor 实例时,我得到了上面的错误。似乎有效的是:
instance functorNonEmpty :: Functor NonEmpty where …Run Code Online (Sandbox Code Playgroud)