<p dir="ltr">You are zipping rather than taking the cross product.</p>
<p dir="ltr"> Ben</p>
<br><div class="gmail_quote"><div dir="ltr">On Fri, 27 Jan 2017, 22:09 sasa bogicevic, <<a href="mailto:brutallesale@gmail.com">brutallesale@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">What is wrong with my applicative instance for custom List type ?<br class="gmail_msg">
<br class="gmail_msg">
<a href="http://lpaste.net/351723" rel="noreferrer" class="gmail_msg" target="_blank">http://lpaste.net/351723</a><br class="gmail_msg">
<br class="gmail_msg">
data List a = Nil | Cons a (List a) deriving (Eq, Show)<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
instance Applicative List where<br class="gmail_msg">
pure x = Cons x Nil<br class="gmail_msg">
Nil <*> _ = Nil<br class="gmail_msg">
_ <*> Nil = Nil<br class="gmail_msg">
(Cons x xy) <*> (Cons z dy) = Cons (x z) (xy <*> dy)<br class="gmail_msg">
<br class="gmail_msg">
Prelude> let functions = Cons (+1) (Cons (*2) Nil)<br class="gmail_msg">
Prelude> let values = Cons 1 (Cons 2 Nil)<br class="gmail_msg">
Prelude> functions <*> values<br class="gmail_msg">
Cons 2 (Cons 3 (Cons 2 (Cons 4 Nil))) -- I get Cons 2 (Cons 4 Nil) what is wrong with my Applicative instance ?<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
{<br class="gmail_msg">
name: Bogicevic Sasa<br class="gmail_msg">
phone: +381606006200<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
Beginners mailing list<br class="gmail_msg">
<a href="mailto:Beginners@haskell.org" class="gmail_msg" target="_blank">Beginners@haskell.org</a><br class="gmail_msg">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" class="gmail_msg" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br class="gmail_msg">
</blockquote></div>