[Haskell-cafe] On to applicative

Thomas Davie tom.davie at gmail.com
Thu Aug 26 03:10:06 EDT 2010

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)

(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)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100826/531f73e4/attachment.html

More information about the Haskell-Cafe mailing list