In search of: [a->b] -> a -> [b]

Graham Klyne GK@ninebynine.org
Wed, 18 Jun 2003 10:40:23 +0100


At 20:15 17/06/03 -0400, Derek Elkins wrote:
>On Tue, 17 Jun 2003 21:01:57 +0100
>Graham Klyne <gk@ninebynine.org> wrote:
>
> > I'm convinced I've seen a function like this somewhere:
> >    [a->b] -> a -> [b]
> > but cannot remember where.  Or maybe:
> >    Monad m => m (a->b) -> a -> m b
> > ?
> >
> > I could roll my own (*), but I'm trying not to duplicate standard
> > library functions is I can help it.  Any pointers?
>
>The closest function I see is ap :: Monad m => m (a -> b) -> m a -> m b

That's the one I was trying to remember!  Thanks.

>   Also you may want to check out the Haskell
>reference at zvon.org, it's indexed by type as well.

Ah!  Very useful.  Thanks again.

> >      flist :: [a->b] -> a -> [b]
> >      flist fs a = map (flip ($) a) fs
>or much nicer (IMO)
>   flist fs a = map ($ a) fs

Ah, yes, I'd not quite grasped that sections can be used "either way" round 
like this.  I agree that's much neater, and this way of combining $ and map 
an idiom that I think could be used in other ways.

>or breakin' out the point-free style,
>   flist = flip (map . flip ($)) -- okay, so I wouldn't recommend this

I keep on reading about this "point free style", but can't find any 
discussion of it.  Are there any pointers (sic) ?

#g


-------------------
Graham Klyne
<GK@NineByNine.org>
PGP: 0FAA 69FF C083 000B A2E9  A131 01B9 1C7A DBCA CB5E