Currently I'm reading PureScript by example book and have question about one of exercises:
Chapter 6, exercise 5 at the end of the chapter.
Write a Foldable instance for NonEmpty. Hint: resuse the foldable instance for arrays.
data NonEmpty a = NonEmpty a (Array a)
My initial thought was to implement it like this:
instance foldableNonEmpty :: Foldable (Array (a)) => Foldable (NonEmpty a) where
foldr f b (NonEmpty a ar) = NonEmpty a (foldr f b ar)
foldl f b (NonEmpty a ar) = NonEmpty a (foldl f b ar)
foldMap m (NonEmpty a ar) = NonEmpty a (foldMap m ar)
But this doesn't work and currently I can't figure out why (compiler error can't help me)
Could not match kind
Type -> Type
with kind
Type
while checking the kind of Foldable (Array a) => Foldable (NonEmpty a)
in value declaration foldableNonEmpty
Can someone point out in which direction should I dig to find an answer?
Foldableis defined forArray. Do you see any differences from your definition? - Fyodor Soikin