
27 Jan
2017
27 Jan
'17
5:09 p.m.
What is wrong with my applicative instance for custom List type ? http://lpaste.net/351723 data List a = Nil | Cons a (List a) deriving (Eq, Show) instance Applicative List where pure x = Cons x Nil Nil <*> _ = Nil _ <*> Nil = Nil (Cons x xy) <*> (Cons z dy) = Cons (x z) (xy <*> dy) Prelude> let functions = Cons (+1) (Cons (*2) Nil) Prelude> let values = Cons 1 (Cons 2 Nil) Prelude> functions <*> values Cons 2 (Cons 3 (Cons 2 (Cons 4 Nil))) -- I get Cons 2 (Cons 4 Nil) what is wrong with my Applicative instance ? { name: Bogicevic Sasa phone: +381606006200 }