<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hmm... it was my understanding that the example was showing how to *avoid* having to create a lot of functions that do the same thing but have different numbers of arguments.<br><br>From the Wiki page:<br><br>"Anytime you feel the need to define different higher order functions to
accommodate for function-arguments with a different number of arguments,
think about how defining a proper instance of <code>Applicative</code> can make your life easier."<br><br>Not so?<br><br>Michael<br><br><br><br>--- On <b>Thu, 8/26/10, Ivan Lazar Miljenovic <i><ivan.miljenovic@gmail.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Ivan Lazar Miljenovic <ivan.miljenovic@gmail.com><br>Subject: Re: [Haskell-cafe] On to applicative<br>To: "michael rice" <nowgate@yahoo.com><br>Cc: haskell-cafe@haskell.org<br>Date: Thursday, August 26, 2010, 2:50 AM<br><br><div class="plainMail">On 26 August 2010 16:47, michael rice <<a ymailto="mailto:nowgate@yahoo.com" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>> wrote:<br>><br>> OK, fmap2 works, but not fmap3. What am I not understanding?<br>><br>> Michael<br>><br>> import Control.Applicative<br>><br>> -- f :: (a -> b -> c)<br>> --
fmap :: Functor f => (d -> e) -> f d -> f e<br>><br>> sumsqr :: Int -> Int -> Int<br>> sumsqr i j = i*i+j*j<br>><br>> -- fmap :: Functor f => f a -> f (b -> c) -- Identify d with a, and e with (b -> c)<br>><br>><br>> fmap2 f a b = f `fmap` a <*> b<br>> fmap3 f a b c = f `fmap` a <*> b <*> c<br>> fmap4 f a b c d = f `fmap` a <*> b <*> c <*> d<br>><br>><br>> -- fmap2 f a b = f <$> a <*> b<br>> -- fmap3 f a b c = f <$> a <*> b <*> c<br>> -- fmap4 f a b c d = f <$> a <*> b <*> c <*> d<br>><br>><br>> *Main> fmap2 sumsqr (Just 3) (Just 4)<br>> Just 25<br>> *Main> fmap3 sumsqr (Just 3) (Just 4) (Just 5)<br>><br>> <interactive>:1:6:<br>> Couldn't match expected type `a2 -> b' against inferred type `Int'<br>>
In the first argument of `fmap3', namely `sumsqr'<br>> In the expression: fmap3 sumsqr (Just 3) (Just 4) (Just 5)<br>> In the definition of `it':<br>> it = fmap3 sumsqr (Just 3) (Just 4) (Just 5)<br>> *Main><br><br>sumsqr takes three arguments; fmap3 has type:<br><br>fmap3 :: (a -> b -> c -> d) -> Maybe a -> Maybe b -> Maybe c -> Maybe d<br><br>i.e. the function you pass it needs to take 3 arguments.<br><br>fmap3 (\ x y z -> z * y + z) (Just 1) (Just 2) (Just 3)<br><br>><br>><br>> --- On Thu, 8/26/10, Ivan Lazar Miljenovic <<a ymailto="mailto:ivan.miljenovic@gmail.com" href="/mc/compose?to=ivan.miljenovic@gmail.com">ivan.miljenovic@gmail.com</a>> wrote:<br>><br>> From: Ivan Lazar Miljenovic <<a ymailto="mailto:ivan.miljenovic@gmail.com"
href="/mc/compose?to=ivan.miljenovic@gmail.com">ivan.miljenovic@gmail.com</a>><br>> Subject: Re: [Haskell-cafe] On to applicative<br>> To: "michael rice" <<a ymailto="mailto:nowgate@yahoo.com" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>><br>> Cc: <a ymailto="mailto:haskell-cafe@haskell.org" href="/mc/compose?to=haskell-cafe@haskell.org">haskell-cafe@haskell.org</a><br>> Date: Thursday, August 26, 2010, 2:33 AM<br>><br>> On 26 August 2010 16:29, michael rice <<a ymailto="mailto:nowgate@yahoo.com" href="/mc/compose?to=nowgate@yahoo.com">nowgate@yahoo.com</a>> wrote:<br>> ><br>> > Can you recommend an example that works?<br>><br>> An example of what?<br>><br>> The definitions of fmap2, etc. on that page look like they're correct.<br>><br>> --<br>> Ivan Lazar Miljenovic<br>> <a ymailto="mailto:Ivan.Miljenovic@gmail.com"
href="/mc/compose?to=Ivan.Miljenovic@gmail.com">Ivan.Miljenovic@gmail.com</a><br>> IvanMiljenovic.wordpress.com<br>><br><br><br><br>--<br>Ivan Lazar Miljenovic<br><a ymailto="mailto:Ivan.Miljenovic@gmail.com" href="/mc/compose?to=Ivan.Miljenovic@gmail.com">Ivan.Miljenovic@gmail.com</a><br>IvanMiljenovic.wordpress.com<br></div></blockquote></td></tr></table><br>