
Hello, is there a function f::[a->b]->a->[b] in the libraries? Couldn't find one using hoogle although this seems to be quite a common thing... Steffen

On 06/06/07, Steffen Mazanek
Hello,
is there a function f::[a->b]->a->[b] in the libraries? Couldn't find one using hoogle although this seems to be quite a common thing...
I asked basically this a few months back. Have a look at http://www.haskell.org/pipermail/haskell-cafe/2007-February/022694.html (and the replies) - hopefully, it will answer your question. If not, if you post a specific example, I'll try to show you what you need to do. Basically, you map ($ arg) over the list of functions. Paul.

Steffen Mazanek wrote:
Hello,
is there a function f::[a->b]->a->[b] in the libraries? Couldn't find one using hoogle although this seems to be quite a common thing...
As far as I know, there is no standard function doing that, though it is easily implemented: mapApply xs x = map ($ x) xs or just: mapApply x = map ($ x) If you don't mind the parameters being reversed. The 'mapApply' name is probably terrible, I'm sure other people would have better suggestions for the naming :-). Cheers, Maxime

On 06/06/07, Steffen Mazanek
Hello,
is there a function f::[a->b]->a->[b] in the libraries? Couldn't find one using hoogle although this seems to be quite a common thing...
Possibly it's just too small to bother putting in a separate function.
let fs = [ (*2), (+2), (2-) ] :t fs fs :: [Integer -> Integer] map ($5) fs [10,7,-3] :t map ($5) map ($5) :: (Num a) => [a -> b] -> [b] let g = \x -> map ($x) :t g g :: a -> [a -> b] -> [b]
That's essentially what you want, but we could go the extra distance.
:t flip g flip g :: [a -> b] -> a -> [b] let h = flip g h fs (5) [10,7,-3]
f fs i = map ($i) fs
D.

Cool! Haskell surprised me once again :)
@Paul: Thank you for pointing me to the old thread.
@Neil: Is there a way to let hoogle find this kind of stuff? It
would be a quite complex inference though.
2007/6/6, apfelmus
Steffen Mazanek wrote:
is there a function f::[a->b]->a->[b] in the libraries?
There is, it's called 'sequence' :) You need to import Control.Monad.Instances though, to get the famous reader monad ((->) a).
Regards, apfelmus
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Dipl.-Inform. Steffen Mazanek Institut für Softwaretechnologie Fakultät Informatik Universität der Bundeswehr München 85577 Neubiberg Tel: +49 (0)89 6004-2505 Fax: +49 (0)89 6004-4447 E-Mail: steffen.mazanek@unibw.de

Hi
@Neil: Is there a way to let hoogle find this kind of stuff? It would be a quite complex inference though.
Finding map ($ x) - no. As soon as you allow combination of functions in various combinations, the search space explodes. For every function you now have id map, id . map f etc - way too many combinations. As for finding sequence with the (->) instance, thats possible. Hoogle 3 is broken when it comes to Monads and higher-kinded type classes. I'm working on fixing this, and once that fix is done, its possible that Hoogle would find the sequence automatically. Thanks Neil

On Wed, Jun 06, 2007 at 03:48:18PM +0200, Steffen Mazanek wrote:
Hello,
is there a function f::[a->b]->a->[b] in the libraries? Couldn't find one using hoogle although this seems to be quite a common thing...
Steffen
Just to add to what others have said, yet another way to implement it is to use list comprehension: mapApply fs x = [f x | f <- fs]
participants (7)
-
apfelmus
-
Dougal Stanton
-
Ilya Tsindlekht
-
Maxime Henrion
-
Neil Mitchell
-
Paul Moore
-
Steffen Mazanek