Question: (I need help with this Scala problem; an explanation with the answer would be greatly appreciated. Thank you.) The simplest rule in combinatory logic is

(I need help with this Scala problem; an explanation with the answer would be greatly appreciated. Thank you.)

The simplest rule in combinatory logic is that any expression of the form () is replaced by its (inner) argument .

For instance, suppose we had a term (())), we can eliminate to obtain (()).

Write a function eliminateICombinator that takes in a Term defined in the grammar above returns a Term that gets rid of all the combinators, as specified above. Please write the function recursively using case pattern matching. Your function should eliminate all the combinators but this can be done in arbitrary order if your expression has multiple such combinators.

Note: ??? indicates that there is a missing function or code fragment that needs to be filled in. In scala, it is also a macro that throws a NotImplemented exception. Make sure that you remove the ??? and replace it with the answer.

// YOUR CODE HERE ???

###TEST

val t1 = Apply( S ( Apply ( K (Variable ("x")), Variable("y"))), I (Variable("x") )) val t1_expected = Apply( S ( Apply ( K (Variable ("x")), Variable("y"))),Variable("x") ) testWithMessage(eliminateICombinator(t1), t1_expected, "# 1 ")

val t2 = Apply( S( I(Variable("x"))), I(I(I(Variable("y"))))) val t2_expected = Apply( S ( Variable("x") ), Variable("y")) testWithMessage(eliminateICombinator(t2), t2_expected, "# 2 ")

val t3 = Apply( K ( Apply ( I (Variable ("x")), Variable("y"))), I (Variable("x") )) val t3_expected = Apply( K ( Apply ( Variable ("x"), Variable("y"))),Variable("x") ) testWithMessage(eliminateICombinator(t3), t3_expected, "# 3 ")

passed(10)

###END TEST

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!