You are zipping rather than taking the cross product.

Ben


On Fri, 27 Jan 2017, 22:09 sasa bogicevic, <brutallesale@gmail.com> wrote:
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
}



_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners