[Haskell-cafe] On to applicative
nowgate at yahoo.com
Thu Aug 26 03:34:08 EDT 2010
A lot of stuff to get one's head around. Was aware of liftM2, liftM3, etc., but not liftA2, liftA3, etc.
So, the statement was true, but not the way that was shown in the example, i.e., with fmap2, fmap3, etc., which required different functions for each of the fmaps.
Thanks. Appreciate the patience.
--- On Thu, 8/26/10, Thomas Davie <tom.davie at gmail.com> wrote:
From: Thomas Davie <tom.davie at gmail.com>
Subject: Re: [Haskell-cafe] On to applicative
To: "michael rice" <nowgate at yahoo.com>
Cc: "Ivan Lazar Miljenovic" <ivan.miljenovic at gmail.com>, haskell-cafe at haskell.org
Date: Thursday, August 26, 2010, 3:10 AM
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."
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 writeliftA3 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)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe