Given the following definition:
data Cons a = Cons a (Cons a)
| Empty
deriving Show
I implemented the following attempt at its Applicative
instance:
instance Applicative Cons where
pure x = Cons x Empty
Empty <*> _ = Empty
(Cons g gs) <*> x = append (fmap g x) (gs <*> x)
append :: Cons a -> Cons a -> Cons a
append Empty x = x
append x Empty = x
append (Cons x Empty) ys = Cons x ys
append (Cons x xs) ys = Cons x (append xs ys)
Please review this implementation - for correctness and whether it's idiomatic/verbose, etc.