Seite 1 von 1

Assignment 4 Task 2

Verfasst: 8. Mai 2014 16:30
von bluefish
Hello,

I got these Results when I'm running my tests.

Test testSample2 failed: Expected App(App(Id('f),Id('a)),Id('b)), but got App(App(Id('f),Id('b)),Id('a))

In my opinion this is the same and I assume the solution wich arranges the parameters backward much more complicated.

So it would be nice to change the tests so that they allow both arrangments.

Re: Assignment 4 Task 2

Verfasst: 8. Mai 2014 16:35
von kim
You are assuming every function to be commutative. Generally speaking f(a,b) and f(b,a) are not the same.

Also I guess there is not so much to change in order to make your solution pass the tests, since the only difference between the two results depends on the direction you traverse the argument list.

Greetings
Kim

Re: Assignment 4 Task 2

Verfasst: 8. Mai 2014 16:50
von bluefish
Ah okay, there is really a fault in my Implementation. But changing the order I'm traversing the list is really ugly in scala as far as I know.

But if the parameter order changes for Fun and App in the same way, the result would be the same. But because this would be a bit unrealistic this should be okay.

Re: Assignment 4 Task 2

Verfasst: 8. Mai 2014 21:13
von Talaron
bluefish hat geschrieben:But changing the order I'm traversing the list is really ugly in scala as far as I know.
That's the reason why using higher-order functions is often less intuitive but actually the superior way of solving many tasks ... ;)


Another question about this task:

When looking at the tests, we are not allowed to preprocess a function without parameters to just it's body. I understand why we are not allowed to do this, and it isn't a problem for function definitions where we can use '_ as "empty" parameter. However, for function applications, don't we have to pass some "placeholder" expression as argument? If I use "Num(0)" or as argument, all tests are passed and the task seems solved. But I could also use "Add(Sub(Num(23), Num(42)), Num(666)))" and the solution is still correct. It just feels weird to me to use some random expression here. Is there a better way to solve this problem?

Re: Assignment 4 Task 2

Verfasst: 8. Mai 2014 23:33
von Dennis Albrecht
I assume that our preprocessor only needs to return a "valid" program if the input was "valid", too (if there is some unbound variable in the input then our preprocessor doesn't somehow correct this either). So it shouldn't matter what pseudo-parameter you use.

Greets Dennis