On 26 Aug 2010, at 08:01, michael rice wrote:

> 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.
> 
> From the Wiki page:
> 
> "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 Applicative can make your life 
> easier."
> 
> Not so?
> 
> 
Very much so – instead of defining liftA2, liftA3 etc like this, just use pure 
to get things into the applicative, and write <*> instead of ' ' to apply 
applicatives and you're done.

Don't write
liftA3 sumsq (Just 3) (Just 4) (Just 5)

Write
(pure sumsq) <*> (pure 3) <*> (pure 4) <*> (pure 5)

or you can get rid of that first pure with a quick fmap:
sumsq <$> (pure 3) <*> (pure 4) <*> (pure 5)

Bob
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to