Selecting Arguments in Function to Feed Map

Dear All, Suppose you have the function f x y z = x*y +z and that you want to iterate it on a list z=[1,2,3,4], with x=4 and y=3 then you would do the following map (f x y) z. Now consider the case in which the list is given by y e.g. y=[1,2,3,4], with x=4 and z=3. How can you iterate f on y (i.e. its second argument) while keeping x and y fixed? Lorenzo

On Mon, Sep 13, 2010 at 14:03, Lorenzo Isella
Dear All, Suppose you have the function
f x y z = x*y +z
and that you want to iterate it on a list z=[1,2,3,4], with x=4 and y=3
then you would do the following
map (f x y) z.
Now consider the case in which the list is given by y e.g.
y=[1,2,3,4], with x=4 and z=3.
How can you iterate f on y (i.e. its second argument) while keeping x and y fixed?
Using a lambda expression (anonymous function) or through clever use of flip. /M -- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe

To actually give the example:
-- assuming that x and z are defined, and ys is the list map (\y -> f x y z) ys
On Mon, Sep 13, 2010 at 9:16 AM, Magnus Therning
On Mon, Sep 13, 2010 at 14:03, Lorenzo Isella
wrote: Dear All, Suppose you have the function
f x y z = x*y +z
and that you want to iterate it on a list z=[1,2,3,4], with x=4 and y=3
then you would do the following
map (f x y) z.
Now consider the case in which the list is given by y e.g.
y=[1,2,3,4], with x=4 and z=3.
How can you iterate f on y (i.e. its second argument) while keeping x and y fixed?
Using a lambda expression (anonymous function) or through clever use of flip.
/M
-- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca|twitter: magthe _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- Alex R

And to finish the example, fully parenthesized: Prelude> let x = 4 Prelude> let y = [1,2,3,4] Prelude> let z = 3 Prelude> map ((flip (f x)) z) y [7,11,15,19] I.e., apply f to x, flip the arguments, apply z, and map the result across y. On 09/13/2010 09:01 AM, Alex Rozenshteyn wrote:
To actually give the example:
-- assuming that x and z are defined, and ys is the list map (\y -> f x y z) ys
On Mon, Sep 13, 2010 at 9:16 AM, Magnus Therning
mailto:magnus@therning.org> wrote: On Mon, Sep 13, 2010 at 14:03, Lorenzo Isella
mailto:lorenzo.isella@gmail.com> wrote: > Dear All, > Suppose you have the function > > f x y z = x*y +z > > and that you want to iterate it on a list > z=[1,2,3,4], with > x=4 and y=3 > > then you would do the following > > map (f x y) z. > > Now consider the case in which the list is given by y e.g. > > y=[1,2,3,4], with > x=4 and z=3. > > How can you iterate f on y (i.e. its second argument) while keeping x and y > fixed? Using a lambda expression (anonymous function) or through clever use of flip.
/M
-- Magnus Therning (OpenPGP: 0xAB4DFBA4) magnus@therning.org Jabber: magnus@therning.org http://therning.org/magnus identi.ca http://identi.ca|twitter: magthe _______________________________________________ Beginners mailing list Beginners@haskell.org mailto:Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- Alex R
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
-- Tommy M. McGuire mcguire@crsr.net

On 13 September 2010 14:03, Lorenzo Isella
How can you iterate f on y (i.e. its second argument) while keeping x and y fixed?
On 13 September 2010 14:16, Magnus Therning
Using a lambda expression (anonymous function) or through clever use of flip.
On 13 September 2010 15:01, Alex Rozenshteyn
To actually give the example:
[example with a lambda expression]
On 13 September 2010 16:33, Tommy M. McGuire
And to finish the example, fully parenthesized:
[example with a clever use of flip] To conclude, Haskell is a great language and has a fantastic user community. Ozgur Akgun
participants (5)
-
Alex Rozenshteyn
-
Lorenzo Isella
-
Magnus Therning
-
Ozgur Akgun
-
Tommy M. McGuire