[Haskell-beginners] applicative instance
sasa bogicevic
brutallesale at gmail.com
Fri Jan 27 22:09:07 UTC 2017
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
}
More information about the Beginners
mailing list