0

I'm trying to do this: Define the function evenOutcome, which applying it with an n number and an m number, returns true if the result of raising n to the number m is even. Note: Solve it using partial application and composition.

I did this: evenOutcome m n = even (m ^ n), which works, but does not satisfy the composition and partial application tasks. To satisfy the tasks I did this: evenOutcome = even.(^), which is clearly wrong.

duplode
  • 33,731
  • 7
  • 79
  • 150
cde33
  • 27
  • 5
  • Hint: `m ^ n` is the same as `(^) m n`. – duplode May 01 '17 at 03:52
  • @duplode (^) m n means the same in prefix notation, but I don't understand how to use it in this case, because I need to use partial application – cde33 May 01 '17 at 04:05
  • 1
    I mentioned the prefix syntax because it makes it a bit easier to see how you are supposed to partially apply `(^)`. – duplode May 01 '17 at 04:10
  • @duplode I tried to do : ` evenOutcome = even.(^) ` because I thought it as prefix notation. – cde33 May 01 '17 at 04:14
  • In your attempt, you are composing functions (with `(.)`), but you aren't doing any partial application. – duplode May 01 '17 at 04:15
  • There is an [algorithm](http://stackoverflow.com/questions/29596285/point-free-problems-in-haskell/29596461#29596461) for making any function normally defined pointfree. – luqui May 01 '17 at 04:23
  • @duplode you were right. New version: evenOutcome n = even.(^n) – cde33 May 01 '17 at 04:38
  • Yup, that's the idea. Note that your new version isn't exactly equivalent to the original one due to the order of the arguments -- for that, you want `evenOutcome m = even . (m ^)`. – duplode May 01 '17 at 04:51
  • @duplode Thanks, I understood the problem – cde33 May 01 '17 at 05:19

0 Answers0