
28 Jan
2017
28 Jan
'17
4:43 a.m.
On Sat, Jan 28, 2017 at 10:09:10AM +0100, sasa bogicevic wrote:
Ok so how would the implementation look to get the correct result ? I can't seem to write something that will compile except ZipList version.
One way is by implementing your own (++): data List a = Nil | Cons a (List a) deriving (Eq, Show) plusPlus :: List a -> List a -> List a plusPlus Nil bs = bs plusPlus (Cons a as) bs = Cons a (as `plusPlus` bs) instance Functor List where fmap f Nil = Nil fmap f (Cons a b) = Cons (f a) (fmap f b) instance Applicative List where pure x = Cons x Nil Nil <*> _ = Nil _ <*> Nil = Nil (Cons x xy) <*> ys = (fmap x ys) `plusPlus` (xy <*> ys)