When I began looking into applicative, I googled "haskell applicative" and 
grabbed the first one on the list, the wikipage. I think a better choice would 
have been the "Learn You a Haskell" section on functors/applicative, the second 
one on the list. I'm going to spend some time there but will no doubt be back 
before long with another question.

Thanks all,

Michael

--- On Thu, 8/26/10, Alexander Solla <[email protected]> wrote:

From: Alexander Solla <[email protected]>
Subject: Re: [Haskell-cafe] On to applicative
To: 
Cc: "haskell-cafe Cafe" <[email protected]>
Date: Thursday, August 26, 2010, 2:15 PM


On Aug 26, 2010, at 9:27 AM, michael rice wrote:
> Some functions just happen to map to other functions.
> 
> <$> is flip fmap.  f <$> functor = fmap f functor  #### Brent Yorgey's post 
> noted.
> 
> #### "map to"? Take as arguments?

"maps to" as in "outputs".

> pure f <*> functor = f <$> functor
> 
> #### Prelude Control.Applicative> pure double <*> (Just 5)
> #### Just 10
> 
> #### Not so, the f got applied or where did we get the 10? Not sure, is this 
> the #### "mistake" you point out in your second post?


double is getting applied in that expression, but it isn't because of pure.  
The <*> operator is pulling double out of pure double (which equals Just double 
in this case), and applying it to Just 5.

My correction was to point out that pure's type is more general than I had 
said.   Instead of
pure :: (a -> b) -> f (a -> b), it is pure :: a -> f a -- which includes (a -> 
b) -> f (a -> b) as a special case.  In fact, pure and return are "essentially 
equivalent" in form.  So you could write out your verification case as

(pure double <*> pure 5) :: Just Int

to further decouple your code from the particular functor you're working with.  
(You need the type annotation to run it in GHCi)

> 
> #### Two ways of doing the same thing?
> 
> #### 1)
> #### Prelude Control.Applicative> (double <$> (Just 7))
> #### Just 14
> 
> #### 2)
> #### Prelude Control.Applicative> pure double <*> (Just 7)
> #### Just 14

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



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

Reply via email to