Re: [Haskell-cafe] Mapping a list of functions
swing map :: forall a b. [a - b] - a - [b] swing any :: forall a. [a - Bool] - a - Bool swing foldr :: forall a b. b - a - [a - b - b] - b swing zipWith :: forall a b c. [a - b - c] - a - [b] - [c] swing find :: forall a. [a - Bool] - a - Maybe (a - Bool) -- applies each of the predicates to the given value, returning the first predicate which succeeds, if any swing partition :: forall a. [a - Bool] - a - ([a - Bool], [a - Bool]) Essentially, the main use case seems to be transforming HOFs that operate on a list of values and a single function into HOFs that operate on a list of functions and a single value. Cheers. ~Liam On 19 June 2010 19:30, Limestraël limestr...@gmail.com wrote: ??? What does exactly swing do ? 2010/6/18 Bulat Ziganshin bulat.zigans...@gmail.com Hello Martin, Thursday, June 17, 2010, 11:02:31 PM, you wrote: But what if I want to apply a list of functions to a single argument. I can one more answer is swing map: http://www.haskell.org/haskellwiki/Pointfree#Swing -- Best regards, Bulat mailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping a list of functions
I love that. It's great. Definitely going in my .ghci file. On 20 June 2010 12:28, Liam O'Connor lia...@cse.unsw.edu.au wrote: swing map :: forall a b. [a - b] - a - [b] swing any :: forall a. [a - Bool] - a - Bool swing foldr :: forall a b. b - a - [a - b - b] - b swing zipWith :: forall a b c. [a - b - c] - a - [b] - [c] swing find :: forall a. [a - Bool] - a - Maybe (a - Bool) -- applies each of the predicates to the given value, returning the first predicate which succeeds, if any swing partition :: forall a. [a - Bool] - a - ([a - Bool], [a - Bool]) Essentially, the main use case seems to be transforming HOFs that operate on a list of values and a single function into HOFs that operate on a list of functions and a single value. Cheers. ~Liam On 19 June 2010 19:30, Limestraël limestr...@gmail.com wrote: ??? What does exactly swing do ? 2010/6/18 Bulat Ziganshin bulat.zigans...@gmail.com Hello Martin, Thursday, June 17, 2010, 11:02:31 PM, you wrote: But what if I want to apply a list of functions to a single argument. I can one more answer is swing map: http://www.haskell.org/haskellwiki/Pointfree#Swing -- Best regards, Bulat mailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping a list of functions
??? What does exactly swing do ? 2010/6/18 Bulat Ziganshin bulat.zigans...@gmail.com Hello Martin, Thursday, June 17, 2010, 11:02:31 PM, you wrote: But what if I want to apply a list of functions to a single argument. I can one more answer is swing map: http://www.haskell.org/haskellwiki/Pointfree#Swing -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping a list of functions
On Jun 17, 2010, at 12:02 PM, Martin Drautzburg wrote: The standard map function applies a single function to a list of arguments. But what if I want to apply a list of functions to a single argument. I can of course write such a function, but I wonder if there is a standard way of doing this, Use Control.Applicative, and the * operator. Something like [f, g, h, i, j] * pure x (which equals [f x, g x, h x, i x , j x]) Related to that is the problem, that the function in map may require more than one argument, so I need to apply it partially to some value(s) first. But what if I want to fix its second and third argument and not its first argument? Can flip help? I think the $ operator can help here. Also, don't forget plain old lambda abstraction to abstract over a free variable. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping a list of functions
Martin.Drautzburg: Hello all The standard map function applies a single function to a list of arguments. But what if I want to apply a list of functions to a single argument. I can of course write such a function, but I wonder if there is a standard way of doing this, map ($ 2) [(*2), (+1), (^7)] Cheers, Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping a list of functions
Martin Drautzburg wrote: Hello all The standard map function applies a single function to a list of arguments. But what if I want to apply a list of functions to a single argument. I can of course write such a function, but I wonder if there is a standard way of doing this, The magical incantation you seek is map ($ x) [fn1, fn2, fn3]. Remember that $ is a function like any other, and can be curried. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping a list of functions
Martin Drautzburg wrote: The standard map function applies a single function to a list of arguments. But what if I want to apply a list of functions to a single argument. So your list of arguments is actually a list of functions. But since functions are first-class values, that shouldn't be a problem. You simply have to write a appropriate function to map over that list of functions: map (\f - f a b c) listOfFunctions The lambda expression (\f - f a b c) denotes a function which takes a function f, and applies it to some values a, b and c. That's exactly the function you want to map over the list of functions. Alternatively, you might want to look into list comprehensions: [f a b c | f - listOfFunctions] Enjoy Haskell! Tillmann ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping a list of functions
listFs = [f1, f2, f3] map ($ x) listFs -- same as [f1 x, f2 x, f3 x] f x y z = ... map (\x - f x u v) xs On 17 Jun 2010, at 23:02, Martin Drautzburg wrote: Hello all The standard map function applies a single function to a list of arguments. But what if I want to apply a list of functions to a single argument. I can of course write such a function, but I wonder if there is a standard way of doing this, Related to that is the problem, that the function in map may require more than one argument, so I need to apply it partially to some value(s) first. But what if I want to fix its second and third argument and not its first argument? Can flip help? Thanks -- Martin ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping a list of functions
Martin Drautzburg martin.drautzb...@web.de writes: Hello all The standard map function applies a single function to a list of arguments. But what if I want to apply a list of functions to a single argument. I can of course write such a function, but I wonder if there is a standard way of doing this, (map ($ 3) [(+2), (*4), (/3)])::[Double] [5.0,12.0,1.0] Related to that is the problem, that the function in map may require more than one argument, so I need to apply it partially to some value(s) first. But what if I want to fix its second and third argument and not its first argument? Can flip help? The pointfree command-line tool can help you find good short forms for this kind of thing: $ pointfree '\x - f x 2 3' flip (flip f 2) 3 In this case the explicit (pointed) lambda is simpler so I would usually just use that. G -- Gregory Collins g...@gregorycollins.net ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping a list of functions
map (\function - function argument) functions map ($ argument) functions map (\firstArgument - function firstArgument secondArgument thirdArgument) xs On 17.06.10 22:02, Martin Drautzburg wrote: Hello all The standard map function applies a single function to a list of arguments. But what if I want to apply a list of functions to a single argument. I can of course write such a function, but I wonder if there is a standard way of doing this, Related to that is the problem, that the function in map may require more than one argument, so I need to apply it partially to some value(s) first. But what if I want to fix its second and third argument and not its first argument? Can flip help -- Best regards, Roman Beslik. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mapping a list of functions
Hello Martin, Thursday, June 17, 2010, 11:02:31 PM, you wrote: But what if I want to apply a list of functions to a single argument. I can one more answer is swing map: http://www.haskell.org/haskellwiki/Pointfree#Swing -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe