[Haskell-beginners] Folding an applicative functor, wait, .. what?

Arlen Cuss celtic at sairyx.org
Sat Jan 8 23:24:53 CET 2011


Hi,

> Initially I didn't even understand how your code worked, but I found a
> small tutorial un this kind of stuff here:
> 
> http://learnyouahaskell.com/functors-applicative-functors-and-monoids#applicative-functors
> 
> Just search for the phrase "Another instance of Applicative is (->) r,
> so functions" and you will see examples similar to yours.

This is actually where I've been learning Haskell from; these parts of
the book sort of half-sunk in, but now that I'm actually trying to use
them it's sinking in better ;-)

> I can't wait for the "Learn You a Haskell" Book!

Would be great!

> Patrick

Cheers,
Arlen

> On Sat, Jan 8, 2011 at 7:45 AM, Arlen Cuss <celtic at sairyx.org> wrote:
> > Hi all,
> >
> > I'm probably in serious trouble here (i.e. I'm toying with things I
> > don't understand); I have some code that I was using like follows,
> > context removed for clarity:
> >
> > anotherFunc :: Int -> String
> > ...
> > map ((++) <$> show <*> anotherFunc) [1..20]
> >
> > This works great - the integers 1..20 are passed to each function and
> > the results are catenated together.
> >
> > What if I'd like to add a third function? So far, the only workable
> > solution I've been able to come up with is this:
> >
> > map ((++) <$> ((++) <$> show <*> anotherFunc) <*> yetAnotherFunc)
> > [1..20]
> >
> > That's one unfortunate expression. I've been messing around with concat
> > (trying to get the results of the functions into a list when all is well
> > and done for concat to finally string together?), but all in all, have
> > not had much luck with seeding the values in that way.
> >
> > I think there is probably an obvious solution I've missed... and hold on
> > a minute!
> >
> > map (mconcat [show, anotherFunc, yetAnotherFunc]) [1..20]
> >
> > I just stumbled upon this. While I'm not 100% confident on what's just
> > happened here, I thought I'd mail this out for everyone to enjoy the
> > learning process that has been this email.
> >
> > This serves as a helpful pointer for me to study both monoids and
> > applicative functors in depth, as the former suddenly leapt out of the
> > recesses of my mind somewhere and solved it.
> >
> > Thanks for listening, and nice to meet you all!
> >
> > Cheers,
> > Arlen
> >
> > _______________________________________________
> > Beginners mailing list
> > Beginners at haskell.org
> > http://www.haskell.org/mailman/listinfo/beginners
> >
> >
> 
> 
> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110109/9921af61/attachment.pgp>


More information about the Beginners mailing list