Assignment 4 Task 2

bluefish
Erstie
Erstie
Beiträge: 11
Registriert: 1. Nov 2012 14:41

Assignment 4 Task 2

Beitrag 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.

kim
Neuling
Neuling
Beiträge: 5
Registriert: 15. Okt 2011 22:05

Re: Assignment 4 Task 2

Beitrag 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

bluefish
Erstie
Erstie
Beiträge: 11
Registriert: 1. Nov 2012 14:41

Re: Assignment 4 Task 2

Beitrag 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.

Talaron
Mausschubser
Mausschubser
Beiträge: 85
Registriert: 26. Apr 2012 11:34

Re: Assignment 4 Task 2

Beitrag 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?

Dennis Albrecht
Sonntagsinformatiker
Sonntagsinformatiker
Beiträge: 222
Registriert: 4. Okt 2010 18:15

Re: Assignment 4 Task 2

Beitrag 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

Antworten

Zurück zu „Archiv“