[Haskell-beginners] applicative instance
Benjamin Edwards
edwards.benj at gmail.com
Fri Jan 27 22:17:35 UTC 2017
You are zipping rather than taking the cross product.
Ben
On Fri, 27 Jan 2017, 22:09 sasa bogicevic, <brutallesale at 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 at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170127/8ab8b4ad/attachment-0001.html>
More information about the Beginners
mailing list