SOE exercise

2002-10-22 Thread Isaac Jones
(I'm not sure why my postings seem somewhat anonymous, I'll mess with
the headers in this post to see if that fixes it.  I post to other
mailman lists and haven't noticed this problem.)

I'm working through Paul Hudak's SOE, and have a question about
problem 9.4, which is to define a function applyEach.  I've come up
with several versions, but not one which usefully uses currying (the
exercise doesn't explicitly say to use currying, but that's the only
thing in this section).

My real question is whether I should be trying to apply currying here.
Solutions are welcome, but I can think of several good reasons not to
post solutions to this forum.

The behavior of applyEach should be obvious from my attempts below.

Output:

applyEach [(+1), (+3), (+2)]  1
= [2,4,3] :: [Integer]

Recursive version:

 applyEach :: [a-b] - a - [b]
 applyEach [] _ = []
 applyEach (h:t) x = (h x) : (applyEach t x)

Now with higher order functions:

 applyEach' :: [a-b] - a - [b]
 applyEach' funs x = map applyx funs where applyx (fun) = fun x

With Lambda:

 applyEach'' :: [a-b] - a - [b]
 applyEach'' funs x = map (\fun- fun x) funs

With Currying:

?

peace,

isaac

P.S. I'm enjoying this book a great deal :-)
___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



Re: SOE exercise

2002-10-22 Thread Hal Daume III
 applyEach [(+1), (+3), (+2)]  1
 = [2,4,3] :: [Integer]
 
  applyEach' :: [a-b] - a - [b]
  applyEach' funs x = map applyx funs where applyx (fun) = fun x

...or more simply:

applyEach' l x = map ($x) l

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe